diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2023-02-02 09:58:36 +0100 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2023-02-02 09:58:36 +0100 |
commit | 4f9c4e93f3a7808cc838cba4cdb460d66d315786 (patch) | |
tree | d9a654fd20e9e75935c450b115076099eb99b857 /example | |
parent | f225dccbd82f48bb1ab10767b9b074e24fedb0f3 (diff) | |
parent | 694ab4eec294a93358f78a349c6df94c3b666126 (diff) | |
download | libayatana-appindicator-4f9c4e93f3a7808cc838cba4cdb460d66d315786.tar.gz libayatana-appindicator-4f9c4e93f3a7808cc838cba4cdb460d66d315786.tar.bz2 libayatana-appindicator-4f9c4e93f3a7808cc838cba4cdb460d66d315786.zip |
Merge branch 'tari01-pr/fix-build-warnings'
Attributes GH PR #59: https://github.com/AyatanaIndicators/libayatana-appindicator/pull/59
Diffstat (limited to 'example')
-rw-r--r-- | example/CMakeLists.txt | 2 | ||||
-rw-r--r-- | example/simple-client-vala.vala | 315 | ||||
-rw-r--r-- | example/simple-client.c | 46 |
3 files changed, 197 insertions, 166 deletions
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index a337cdc..0b5f133 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -31,7 +31,7 @@ if (FLAVOUR_GTK3) # simple-client-vala - set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/simple-client-vala.c" PROPERTIES COMPILE_FLAGS " -include ${CMAKE_SOURCE_DIR}/src/app-indicator.h") + set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/simple-client-vala.c" PROPERTIES COMPILE_FLAGS " -include ${CMAKE_SOURCE_DIR}/src/app-indicator.h -Wno-incompatible-pointer-types -Wno-unused-but-set-variable") add_executable("simple-client-vala" "${CMAKE_CURRENT_BINARY_DIR}/simple-client-vala.c") target_include_directories("simple-client-vala" PUBLIC ${PROJECT_DEPS_INCLUDE_DIRS}) target_link_libraries("simple-client-vala" "${PROJECT_DEPS_LIBRARIES} -l${ayatana_appindicator_gtkver} -L${CMAKE_BINARY_DIR}/src") diff --git a/example/simple-client-vala.vala b/example/simple-client-vala.vala index c30bf34..5b3af11 100644 --- a/example/simple-client-vala.vala +++ b/example/simple-client-vala.vala @@ -3,20 +3,22 @@ A small piece of sample code demonstrating a very simple application with an indicator. Copyright 2011 Canonical Ltd. +Copyright 2022 Robert Tari Authors: Marco Trevisan <mail@3v1n0.net> + Robert Tari <robert@tari.in> -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -24,159 +26,166 @@ using Gtk; using AppIndicator; static int main(string[] args) { - var sc = new SimpleClient(args); - sc.run(); - return 0; + var sc = new SimpleClient(args); + sc.run(); + return 0; } class SimpleClient { - Gtk.Menu menu; - Indicator ci; - int percentage; - bool active; - bool can_haz_label; + Gtk.Menu menu; + Indicator ci; + int percentage; + bool active; + bool can_haz_label; - public SimpleClient(string[] args) { - Gtk.init(ref args); + public SimpleClient(string[] args) { + Gtk.init(ref args); - ci = new Indicator("example-simple-client", + ci = new Indicator("example-simple-client", "indicator-messages", IndicatorCategory.APPLICATION_STATUS); - ci.set_status(IndicatorStatus.ACTIVE); - ci.set_attention_icon("indicator-messages-new"); - ci.set_label("1%", "100%"); - ci.set_title("Test Indicator (vala)"); - - active = true; - can_haz_label = true; - } - - private void toggle_sensitivity(Widget widget) { - widget.set_sensitive(!widget.is_sensitive()); - } - - private void append_submenu(Gtk.MenuItem item) { - var menu = new Gtk.Menu(); - Gtk.MenuItem mi; - - mi = new Gtk.MenuItem.with_label("Sub 1"); - menu.append(mi); - mi.activate.connect(() => { print("Sub1\n"); }); - - Gtk.MenuItem prev_mi = mi; - mi = new Gtk.MenuItem.with_label("Sub 2"); - menu.append(mi); - mi.activate.connect(() => { toggle_sensitivity(prev_mi); }); - - mi = new Gtk.MenuItem.with_label("Sub 3"); - menu.append(mi); - mi.activate.connect(() => { print("Sub3\n"); }); - - mi = new Gtk.MenuItem.with_label("Toggle Attention"); - menu.append(mi); - mi.activate.connect(() => { - if (ci.get_status() == IndicatorStatus.ATTENTION) - ci.set_status(IndicatorStatus.ACTIVE); - else - ci.set_status(IndicatorStatus.ATTENTION); - }); - - ci.set_secondary_activate_target(mi); - - menu.show_all(); - item.set_submenu(menu); - } - - private void label_toggle(Gtk.MenuItem item) { - can_haz_label = !can_haz_label; - - if (can_haz_label) { - item.set_label("Hide label"); - } else { - item.set_label("Show label"); - } - } - - public void run() { - - ci.scroll_event.connect((delta, direction) => { - print(@"Got scroll event! delta: $delta, direction: $direction\n"); - }); - - GLib.Timeout.add_seconds(1, () => { - percentage = (percentage + 1) % 100; - if (can_haz_label) { - ci.set_label(@"$(percentage+1)%", ""); - } else { - ci.set_label("", ""); - } - return true; - }); - - menu = new Gtk.Menu(); - var chk = new CheckMenuItem.with_label("1"); - chk.activate.connect(() => { print("1\n"); }); - menu.append(chk); - chk.show(); - - var radio = new Gtk.RadioMenuItem.with_label(new SList<RadioMenuItem>(), "2"); - radio.activate.connect(() => { print("2\n"); }); - menu.append(radio); - radio.show(); - - var submenu = new Gtk.MenuItem.with_label("3"); - menu.append(submenu); - append_submenu(submenu); - submenu.show(); - - var toggle_item = new Gtk.MenuItem.with_label("Toggle 3"); - toggle_item.activate.connect(() => { toggle_sensitivity(submenu); }); - menu.append(toggle_item); - toggle_item.show(); - - var imgitem = new Gtk.ImageMenuItem.from_stock(Stock.NEW, null); - imgitem.activate.connect(() => { - Image img = (Image) imgitem.get_image(); - img.set_from_stock(Stock.OPEN, IconSize.MENU); - }); - menu.append(imgitem); - imgitem.show(); - - var att = new Gtk.MenuItem.with_label("Get Attention"); - att.activate.connect(() => { - if (active) { - ci.set_status(IndicatorStatus.ATTENTION); - att.set_label("I'm okay now"); - active = false; - } else { - ci.set_status(IndicatorStatus.ACTIVE); - att.set_label("Get Attention"); - active = false; - } - }); - menu.append(att); - att.show(); - - var show = new Gtk.MenuItem.with_label("Show Label"); - label_toggle(show); - show.activate.connect(() => { label_toggle(show); }); - menu.append(show); - show.show(); - - var icon = new Gtk.CheckMenuItem.with_label("Set Local Icon"); - icon.activate.connect(() => { - if (icon.get_active()) { - ci.set_icon("simple-client-test-icon.png"); - } else { - ci.set_icon("indicator-messages"); - } - }); - menu.append(icon); - icon.show(); - - ci.set_menu(menu); - - Gtk.main(); - } + ci.set_status(IndicatorStatus.ACTIVE); + ci.set_attention_icon_full("indicator-messages-new", null); + ci.set_label("1%", "100%"); + ci.set_title("Test Indicator (vala)"); + + active = true; + can_haz_label = true; + } + + private void toggle_sensitivity(Widget widget) { + widget.set_sensitive(!widget.is_sensitive()); + } + + private void append_submenu(Gtk.MenuItem item) { + var menu = new Gtk.Menu(); + Gtk.MenuItem mi; + + mi = new Gtk.MenuItem.with_label("Sub 1"); + menu.append(mi); + mi.activate.connect(() => { print("Sub1\n"); }); + + Gtk.MenuItem prev_mi = mi; + mi = new Gtk.MenuItem.with_label("Sub 2"); + menu.append(mi); + mi.activate.connect(() => { toggle_sensitivity(prev_mi); }); + + mi = new Gtk.MenuItem.with_label("Sub 3"); + menu.append(mi); + mi.activate.connect(() => { print("Sub3\n"); }); + + mi = new Gtk.MenuItem.with_label("Toggle Attention"); + menu.append(mi); + mi.activate.connect(() => { + if (ci.get_status() == IndicatorStatus.ATTENTION) + ci.set_status(IndicatorStatus.ACTIVE); + else + ci.set_status(IndicatorStatus.ATTENTION); + }); + + ci.set_secondary_activate_target(mi); + + menu.show_all(); + item.set_submenu(menu); + } + + private void label_toggle(Gtk.MenuItem item) { + can_haz_label = !can_haz_label; + + if (can_haz_label) { + item.set_label("Hide label"); + } else { + item.set_label("Show label"); + } + } + + public void run() { + + ci.scroll_event.connect((delta, direction) => { + print(@"Got scroll event! delta: $delta, direction: $direction\n"); + }); + + GLib.Timeout.add_seconds(1, () => { + percentage = (percentage + 1) % 100; + if (can_haz_label) { + ci.set_label(@"$(percentage+1)%", ""); + } else { + ci.set_label("", ""); + } + return true; + }); + + menu = new Gtk.Menu(); + var chk = new CheckMenuItem.with_label("1"); + chk.activate.connect(() => { print("1\n"); }); + menu.append(chk); + chk.show(); + + var radio = new Gtk.RadioMenuItem.with_label(new SList<RadioMenuItem>(), "2"); + radio.activate.connect(() => { print("2\n"); }); + menu.append(radio); + radio.show(); + + var submenu = new Gtk.MenuItem.with_label("3"); + menu.append(submenu); + append_submenu(submenu); + submenu.show(); + + var toggle_item = new Gtk.MenuItem.with_label("Toggle 3"); + toggle_item.activate.connect(() => { toggle_sensitivity(submenu); }); + menu.append(toggle_item); + toggle_item.show(); + + var pImage = new Gtk.Image.from_icon_name("document-new", IconSize.MENU); + var pLabel = new Gtk.Label("New"); + var pGrid = new Gtk.Grid(); + pGrid.add(pImage); + pGrid.add(pLabel); + var imgitem = new Gtk.MenuItem(); + imgitem.add(pGrid); + imgitem.activate.connect(() => { + Grid pGridLocal = (Grid)imgitem.get_children().nth_data(0); + Image img = (Image) pGridLocal.get_children().nth_data(1); + img.set_from_icon_name("document-open", IconSize.MENU); + }); + menu.append(imgitem); + imgitem.show(); + + var att = new Gtk.MenuItem.with_label("Get Attention"); + att.activate.connect(() => { + if (active) { + ci.set_status(IndicatorStatus.ATTENTION); + att.set_label("I'm okay now"); + active = false; + } else { + ci.set_status(IndicatorStatus.ACTIVE); + att.set_label("Get Attention"); + active = false; + } + }); + menu.append(att); + att.show(); + + var show = new Gtk.MenuItem.with_label("Show Label"); + label_toggle(show); + show.activate.connect(() => { label_toggle(show); }); + menu.append(show); + show.show(); + + var icon = new Gtk.CheckMenuItem.with_label("Set Local Icon"); + icon.activate.connect(() => { + if (icon.get_active()) { + ci.set_icon_full("simple-client-test-icon.png", null); + } else { + ci.set_icon_full("indicator-messages", null); + } + }); + menu.append(icon); + icon.show(); + + ci.set_menu(menu); + + Gtk.main(); + } } diff --git a/example/simple-client.c b/example/simple-client.c index 6d67955..78a560d 100644 --- a/example/simple-client.c +++ b/example/simple-client.c @@ -3,20 +3,22 @@ A small piece of sample code demonstrating a very simple application with an indicator. Copyright 2009 Canonical Ltd. +Copyright 2022 Robert Tari Authors: Ted Gould <ted@canonical.com> + Robert Tari <robert@tari.in> -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -92,9 +94,15 @@ toggle_sensitivity_cb (GtkWidget *widget, gpointer data) static void image_clicked_cb (GtkWidget *widget, gpointer data) { - gtk_image_set_from_stock (GTK_IMAGE (gtk_image_menu_item_get_image ( - GTK_IMAGE_MENU_ITEM (widget))), - GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU); + GList *pList = gtk_container_get_children(GTK_CONTAINER(widget)); + GtkContainer *pContainer = GTK_CONTAINER(g_list_nth_data(pList, 0)); + pList = gtk_container_get_children(pContainer); +#if GTK_MAJOR_VERSION >= 3 + GtkImage *pImage = GTK_IMAGE(g_list_nth_data(pList, 1)); +#else + GtkImage *pImage = GTK_IMAGE(g_list_nth_data(pList, 0)); +#endif + gtk_image_set_from_icon_name(pImage, "document-open", GTK_ICON_SIZE_MENU); } static void @@ -161,13 +169,13 @@ main (int argc, char ** argv) "indicator-messages", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); - g_assert (IS_APP_INDICATOR (ci)); + g_assert (APP_IS_INDICATOR (ci)); g_assert (G_IS_OBJECT (ci)); app_indicator_set_status (ci, APP_INDICATOR_STATUS_ACTIVE); app_indicator_set_attention_icon_full(ci, "indicator-messages-new", "System Messages Icon Highlighted"); app_indicator_set_label (ci, "1%", "100%"); - app_indicator_set_title (ci, "Test Inidcator"); + app_indicator_set_title (ci, "Test Inidcator"); g_signal_connect (ci, "scroll-event", G_CALLBACK (scroll_event_cb), NULL); @@ -198,7 +206,21 @@ main (int argc, char ** argv) gtk_menu_shell_append (GTK_MENU_SHELL (menu), toggle_item); gtk_widget_show(toggle_item); - item = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL); + GtkWidget *pImage = gtk_image_new_from_icon_name("document-new", GTK_ICON_SIZE_MENU); + GtkWidget *pLabel = gtk_label_new("New"); +#if GTK_MAJOR_VERSION >= 3 + GtkWidget *pGrid = gtk_grid_new(); + gtk_container_add(GTK_CONTAINER(pGrid), pImage); + gtk_container_add(GTK_CONTAINER(pGrid), pLabel); + item = gtk_menu_item_new(); + gtk_container_add(GTK_CONTAINER(item), pGrid); +#else + GtkWidget *pBox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(pBox), pImage, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(pBox), pLabel, FALSE, FALSE, 0); + item = gtk_menu_item_new(); + gtk_container_add(GTK_CONTAINER(item), pBox); +#endif g_signal_connect (item, "activate", G_CALLBACK (image_clicked_cb), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); |