summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/task_manager_gtk.h
blob: f4ebf2a864708b805c93e6032a84bce301c340ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_
#define CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_

#include <gtk/gtk.h>

#include <string>

#include "chrome/browser/task_manager.h"

class TaskManagerGtk : public TaskManagerModelObserver {
 public:
  TaskManagerGtk();
  virtual ~TaskManagerGtk();

  // TaskManagerModelObserver
  virtual void OnModelChanged();
  virtual void OnItemsChanged(int start, int length);
  virtual void OnItemsAdded(int start, int length);
  virtual void OnItemsRemoved(int start, int length);

  // Creates the task manager if it doesn't exist; otherwise, it activates the
  // existing task manager window.
  static void Show();

 private:
  class ContextMenuController;
  friend class ContextMenuController;

  // Initializes the task manager dialog.
  void Init();

  // Set |dialog_|'s initial size, using its previous size if that was saved.
  void SetInitialDialogSize();

  // Connects the ctrl-w accelerator to the dialog.
  void ConnectAccelerators();

  // Sets up the treeview widget.
  void CreateTaskManagerTreeview();

  // Returns the model data for a given |row| and |col_id|.
  std::string GetModelText(int row, int col_id);

  // Retrieves the resource icon from the model for |row|.
  GdkPixbuf* GetModelIcon(int row);

  // Sets the treeview row data.  |row| is an index into the model and |iter|
  // is the current position in the treeview.
  void SetRowDataFromModel(int row, GtkTreeIter* iter);

  // Queries the treeview for the selected rows, and kills those processes.
  void KillSelectedProcesses();

  // Opens the context menu used to select the task manager columns.
  void ShowContextMenu();

  // Activates the tab associated with the focused row.
  void ActivateFocusedTab();

  // Opens about:memory in a new foreground tab.
  void OnLinkActivated();

  // response signal handler that notifies us of dialog responses.
  static void OnResponse(GtkDialog* dialog, gint response_id,
                         TaskManagerGtk* task_manager);

  // changed signal handler that is sent when the treeview selection changes.
  static void OnSelectionChanged(GtkTreeSelection* selection,
                                 TaskManagerGtk* task_manager);

  // button-press-event handler that activates a process on double-click.
  static gboolean OnButtonPressEvent(GtkWidget* widget, GdkEventButton* event,
                                     TaskManagerGtk* task_manager);

  // button-release-event handler that opens the right-click context menu.
  static gboolean OnButtonReleaseEvent(GtkWidget* widget, GdkEventButton* event,
                                       TaskManagerGtk* task_manager);

  // Handles an accelerator being pressed.
  static gboolean OnGtkAccelerator(GtkAccelGroup* accel_group,
                                   GObject* acceleratable,
                                   guint keyval,
                                   GdkModifierType modifier,
                                   TaskManagerGtk* task_manager);

  // The task manager.
  TaskManager* task_manager_;

  // Our model.
  TaskManagerModel* model_;

  // The task manager dialog window.
  GtkWidget* dialog_;

  // The treeview that contains the process list.
  GtkWidget* treeview_;

  // The list of processes.
  GtkListStore* process_list_;

  // The number of processes in |process_list_|.
  int process_count_;

  // The context menu controller.
  scoped_ptr<ContextMenuController> menu_controller_;

  // An open task manager window. There can only be one open at a time. This
  // is reset to NULL when the window is closed.
  static TaskManagerGtk* instance_;

  DISALLOW_COPY_AND_ASSIGN(TaskManagerGtk);
};

#endif  // CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_