2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-05-30 10:31:27 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-07-10 13:06:41 +08:00
|
|
|
#include "atom/browser/ui/tray_icon_gtk.h"
|
|
|
|
|
2016-06-20 17:35:45 +09:00
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
2014-07-10 13:06:41 +08:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "chrome/browser/ui/libgtk2ui/app_indicator_icon.h"
|
|
|
|
#include "chrome/browser/ui/libgtk2ui/gtk2_status_icon.h"
|
2015-01-02 19:17:02 -08:00
|
|
|
#include "ui/gfx/image/image.h"
|
2014-05-30 10:31:27 +08:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2016-06-20 17:35:45 +09:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Number of app indicators used (used as part of app-indicator id).
|
|
|
|
int indicators_count;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-07-10 13:06:41 +08:00
|
|
|
TrayIconGtk::TrayIconGtk() {
|
|
|
|
}
|
|
|
|
|
|
|
|
TrayIconGtk::~TrayIconGtk() {
|
|
|
|
}
|
|
|
|
|
2015-01-02 18:43:56 -08:00
|
|
|
void TrayIconGtk::SetImage(const gfx::Image& image) {
|
2014-07-10 13:06:41 +08:00
|
|
|
if (icon_) {
|
2015-01-02 18:43:56 -08:00
|
|
|
icon_->SetImage(image.AsImageSkia());
|
2014-07-10 13:06:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::string16 empty;
|
2016-06-20 17:35:45 +09:00
|
|
|
if (libgtk2ui::AppIndicatorIcon::CouldOpen()) {
|
|
|
|
++indicators_count;
|
2015-01-02 19:17:02 -08:00
|
|
|
icon_.reset(new libgtk2ui::AppIndicatorIcon(
|
2016-06-20 17:35:45 +09:00
|
|
|
base::StringPrintf(
|
|
|
|
"%s%d", Browser::Get()->GetName().c_str(), indicators_count),
|
|
|
|
image.AsImageSkia(),
|
|
|
|
empty));
|
|
|
|
} else {
|
2015-01-02 19:17:02 -08:00
|
|
|
icon_.reset(new libgtk2ui::Gtk2StatusIcon(image.AsImageSkia(), empty));
|
2016-06-20 17:35:45 +09:00
|
|
|
}
|
2014-07-10 13:06:41 +08:00
|
|
|
icon_->set_delegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
|
|
|
|
icon_->SetToolTip(base::UTF8ToUTF16(tool_tip));
|
|
|
|
}
|
|
|
|
|
2016-07-06 16:04:18 -07:00
|
|
|
void TrayIconGtk::SetContextMenu(AtomMenuModel* menu_model) {
|
2014-07-10 13:06:41 +08:00
|
|
|
icon_->UpdatePlatformContextMenu(menu_model);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrayIconGtk::OnClick() {
|
2015-05-21 15:22:52 +08:00
|
|
|
NotifyClicked();
|
2014-07-10 13:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TrayIconGtk::HasClickAction() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-30 23:57:54 +08:00
|
|
|
// static
|
|
|
|
TrayIcon* TrayIcon::Create() {
|
2014-07-10 13:06:41 +08:00
|
|
|
return new TrayIconGtk;
|
2014-05-30 23:57:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-30 10:31:27 +08:00
|
|
|
} // namespace atom
|