1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
6#define CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
7
8#include "base/files/file_path.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/memory/weak_ptr.h"
11#include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
12#include "ui/views/linux_ui/status_icon_linux.h"
13
14typedef struct _AppIndicator AppIndicator;
15typedef struct _GtkWidget GtkWidget;
16
17namespace gfx {
18class ImageSkia;
19}
20
21namespace ui {
22class MenuModel;
23}
24
25namespace libgtk2ui {
26class AppIndicatorIconMenu;
27
28// Status icon implementation which uses libappindicator.
29class AppIndicatorIcon : public views::StatusIconLinux {
30 public:
31  // The id uniquely identifies the new status icon from other chrome status
32  // icons.
33  AppIndicatorIcon(std::string id,
34                   const gfx::ImageSkia& image,
35                   const base::string16& tool_tip);
36  virtual ~AppIndicatorIcon();
37
38  // Indicates whether libappindicator so could be opened.
39  static bool CouldOpen();
40
41  // Overridden from views::StatusIconLinux:
42  virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
43  virtual void SetToolTip(const base::string16& tool_tip) OVERRIDE;
44  virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE;
45  virtual void RefreshPlatformContextMenu() OVERRIDE;
46
47 private:
48  void SetImageFromFile(const base::FilePath& icon_file_path);
49  void SetMenu();
50
51  // Sets a menu item at the top of the menu as a replacement for the status
52  // icon click action. Clicking on this menu item should simulate a status icon
53  // click by despatching a click event.
54  void UpdateClickActionReplacementMenuItem();
55
56  // Callback for when the status icon click replacement menu item is activated.
57  void OnClickActionReplacementMenuItemActivated();
58
59  std::string id_;
60  std::string tool_tip_;
61
62  // Whether the user is using KDE.
63  bool using_kde4_;
64
65  // Gtk status icon wrapper
66  AppIndicator* icon_;
67
68  scoped_ptr<AppIndicatorIconMenu> menu_;
69  ui::MenuModel* menu_model_;
70
71  base::FilePath icon_file_path_;
72  int icon_change_count_;
73
74  base::WeakPtrFactory<AppIndicatorIcon> weak_factory_;
75
76  DISALLOW_COPY_AND_ASSIGN(AppIndicatorIcon);
77};
78
79}  // namespace libgtk2ui
80
81#endif  // CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
82