コード例 #1
0
 private void changeIcon(final String fileName, final String label) {
   libappindicator.app_indicator_set_icon_full(appIndicator, iconPath(fileName), "Lantern");
   libgtk.gtk_menu_item_set_label(connectionStatusItem, label);
 }
コード例 #2
0
  @Override
  public void createTray() {

    /*uniqueApp = libunique.unique_app_new("org.lantern.lantern", null);
    if (libunique.unique_app_is_running(uniqueApp)) {
        LOG.error("Already running!");
        System.exit(0);
        // could signal to open dashboard
    }*/

    menu = libgtk.gtk_menu_new();

    connectionStatusItem = libgtk.gtk_menu_item_new_with_label(LABEL_DISCONNECTED);
    libgtk.gtk_widget_set_sensitive(connectionStatusItem, Gtk.FALSE);
    libgtk.gtk_menu_shell_append(menu, connectionStatusItem);
    libgtk.gtk_widget_show_all(connectionStatusItem);

    dashboardItem = libgtk.gtk_menu_item_new_with_label("Open Dashboard");
    dashboardItemCallback =
        new Gobject.GCallback() {
          @Override
          public void callback(Pointer instance, Pointer data) {
            LOG.debug("openDashboardItem callback called");
            openDashboard();
          }
        };
    libgobject.g_signal_connect_data(
        dashboardItem, "activate", dashboardItemCallback, null, null, 0);
    libgtk.gtk_menu_shell_append(menu, dashboardItem);
    libgtk.gtk_widget_show_all(dashboardItem);

    // updateItem = Gtk.gtk_menu_item_new_with_label();

    quitItem = libgtk.gtk_menu_item_new_with_label("Quit");
    quitItemCallback =
        new Gobject.GCallback() {
          @Override
          public void callback(Pointer instance, Pointer data) {
            LOG.debug("quitItemCallback called");
            quit();
          }
        };
    libgobject.g_signal_connect_data(quitItem, "activate", quitItemCallback, null, null, 0);
    libgtk.gtk_menu_shell_append(menu, quitItem);
    libgtk.gtk_widget_show_all(quitItem);

    appIndicator =
        libappindicator.app_indicator_new(
            "lantern", "indicator-messages-new", AppIndicator.CATEGORY_APPLICATION_STATUS);

    /* XXX basically a hack -- we should subclass the AppIndicator
       type and override the fallback entry in the 'vtable', instead we just
       hack the app indicator class itself. Not an issue unless we need other
       appindicators.
    */
    AppIndicator.AppIndicatorClassStruct aiclass =
        new AppIndicator.AppIndicatorClassStruct(appIndicator.parent.g_type_instance.g_class);

    AppIndicator.Fallback replacementFallback =
        new AppIndicator.Fallback() {
          @Override
          public Pointer callback(final AppIndicator.AppIndicatorInstanceStruct self) {
            fallback();
            return null;
          }
        };

    aiclass.fallback = replacementFallback;
    aiclass.write();

    libappindicator.app_indicator_set_menu(appIndicator, menu);

    changeIcon(ICON_DISCONNECTED, LABEL_DISCONNECTED);
    libappindicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE);

    Events.register(this);
    this.active = true;
  }