AwnApplet* awn_applet_factory_initp(const gchar *name, const gchar* uid, gint panel_id) { AwnApplet *applet = AWN_APPLET(awn_applet_simple_new(name, uid, panel_id)); CpuMeter *cpumeter; g_object_set (applet, "display-name","Awn System Monitor", NULL); gint height = awn_applet_get_size(applet); gtk_widget_set_size_request(GTK_WIDGET(applet), height*1.25, -1); GdkPixbuf *icon; #if 0 icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "gnome-main-menu", height - 2, 0, NULL); awn_applet_simple_set_temp_icon(AWN_APPLET_SIMPLE(applet), icon); #endif /*setting to a transparent pixbuf to begin with... awn-effects (I think) does not seem to deal well with having the icon set overly late*/ #if 1 icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, height, height); gdk_pixbuf_fill(icon, 0x00000000); awn_applet_simple_set_icon_pixbuf(AWN_APPLET_SIMPLE(applet), icon); #endif cpumeter = cpumeter_applet_new(applet); cpumeter->height = height; /*gtk_widget_show_all(GTK_WIDGET(applet));*/ return applet; }
static void awn_applet_simple_constructed (GObject *object) { G_OBJECT_CLASS (awn_applet_simple_parent_class)->constructed (object); AwnAppletSimple *applet = AWN_APPLET_SIMPLE (object); AwnAppletSimplePrivate *priv = applet->priv; gchar *applet_name; g_object_get (object, "canonical-name",&applet_name, NULL); priv->icon = awn_themed_icon_new (); g_object_set (priv->icon, "applet-name",applet_name, NULL); awn_icon_set_pos_type (AWN_ICON (priv->icon), awn_applet_get_pos_type (AWN_APPLET (object))); awn_icon_set_offset (AWN_ICON (priv->icon), awn_applet_get_offset (AWN_APPLET (object))); g_signal_connect_swapped (priv->icon, "clicked", G_CALLBACK (on_icon_clicked), object); g_signal_connect_swapped (priv->icon, "middle-clicked", G_CALLBACK (on_icon_middle_clicked), object); g_signal_connect_swapped (priv->icon, "context-menu-popup", G_CALLBACK (on_icon_menu_popup), object); gtk_container_add (GTK_CONTAINER (applet), priv->icon); gtk_widget_show (priv->icon); g_free (applet_name); }
/* * When the position changes, we need to update the size of the applet */ static void awn_applet_simple_position_changed (AwnApplet *applet, GtkPositionType position) { AwnAppletSimplePrivate *priv = AWN_APPLET_SIMPLE (applet)->priv; if (AWN_IS_ICON (priv->icon)) { awn_icon_set_pos_type (AWN_ICON (priv->icon), position); } }
static void site_clicked(GtkButton *button, WebSite *site) { go_to_url(site->webapplet, site->url); gint size = awn_applet_get_size(site->webapplet->applet); gchar *path = g_strdup_printf(APPLETSDIR"/webapplet/icons/%s", site->icon); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(path, size, size, NULL); awn_applet_simple_set_icon_pixbuf(AWN_APPLET_SIMPLE(site->webapplet->applet), pixbuf); if (site->width && site->height) { gtk_widget_set_size_request(GTK_WIDGET(site->webapplet->box), site->width, site->height); } /* Set as new home page if this is either in the main menu, or * in the dialog with 'set as new home page' checked */ if (!GTK_IS_WIDGET(site->webapplet->check_home) || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(site->webapplet->check_home))) { config_set_uri(site->webapplet, site->url); config_set_site(site->webapplet, site->name); if (GTK_IS_WIDGET(site->webapplet->location_dialog)) gtk_widget_destroy(site->webapplet->location_dialog); } if (GTK_IS_WIDGET(site->webapplet->location_dialog)) gtk_widget_destroy(site->webapplet->location_dialog); else config_set_first_start(site->webapplet, FALSE); /* Set the title to the name of the website */ awn_applet_simple_set_tooltip_text(AWN_APPLET_SIMPLE(site->webapplet->applet), site->name); g_free(path); }
static void awn_applet_simple_size_changed (AwnApplet *applet, gint size) { AwnAppletSimplePrivate *priv = AWN_APPLET_SIMPLE (applet)->priv; if (!AWN_IS_ICON (priv->icon)) return; if (priv->last_set_icon == ICON_THEMED_SIMPLE || priv->last_set_icon == ICON_THEMED_MANY) awn_themed_icon_set_size (AWN_THEMED_ICON (priv->icon), size); awn_applet_simple_position_changed (applet, awn_applet_get_pos_type (applet)); }
static void awn_applet_simple_offset_changed (AwnApplet *applet, gint offset) { AwnAppletSimplePrivate *priv = AWN_APPLET_SIMPLE (applet)->priv; if (AWN_IS_ICON (priv->icon)) { GtkAllocation alloc; gtk_widget_get_allocation (GTK_WIDGET (priv->icon), &alloc); gint x = alloc.x + alloc.width / 2; gint y = alloc.y + alloc.height / 2; offset = awn_applet_get_offset_at (applet, x, y); awn_icon_set_offset (AWN_ICON (priv->icon), offset); } }
static void set_title(WebApplet *webapplet, const gchar *uri) { gchar *title = NULL; if (g_str_has_prefix(uri, "http://")) title = g_strdup(uri + 7); else if (g_str_has_prefix(uri, "https://")) title = g_strdup(uri + 8); else title = g_strdup(uri); /* Truncate at any '/' */ title[strcspn(title, "/")] = '\0'; awn_applet_simple_set_tooltip_text(AWN_APPLET_SIMPLE(webapplet->applet), title); g_free(title); }
AwnApplet * awn_applet_factory_initp (const gchar *name, gchar* uid, gint panel_id) { g_on_error_stack_trace (NULL); html_init (); WebApplet *webapplet = g_malloc (sizeof (WebApplet)); webapplet->uid=g_strdup(uid); webapplet->check_home = NULL; webapplet->location_dialog = NULL; webapplet->start = NULL; webapplet->applet = AWN_APPLET (awn_applet_simple_new (name, uid, panel_id)); init_config (webapplet); gint height = awn_applet_get_size(webapplet->applet); awn_applet_simple_set_icon_name(AWN_APPLET_SIMPLE(webapplet->applet), ICON_NAME); /*gtk_widget_show_all (GTK_WIDGET (webapplet->applet));*/ awn_html_dialog_new (webapplet); gtk_window_set_focus_on_map (GTK_WINDOW (webapplet->mainwindow), TRUE); g_signal_connect_after (G_OBJECT (webapplet->applet), "realize", G_CALLBACK (_bloody_thing_has_style), webapplet); return webapplet->applet; }
static void awn_html_dialog_new(WebApplet *webapplet) { /* create viewer */ webapplet->mainwindow = awn_dialog_new_for_widget (GTK_WIDGET(webapplet->applet)); webapplet->box = gtk_vbox_new (FALSE, 1); webapplet->viewer = html_web_view_new (); /* Load the .ini file for websites */ GError *err = NULL; webapplet->sites_file = g_key_file_new(); g_key_file_load_from_file(webapplet->sites_file, APPLETSDIR"/webapplet/webapplet-websites.ini", 0, &err); if (err) { printf("Error loading websites: %s\n", err->message); g_error_free(err); g_key_file_free(webapplet->sites_file); webapplet->sites_file = NULL; } /* If first time using this, hide WebView, show location entry/website buttons */ if (config_get_first_start(webapplet)) { gtk_widget_set_no_show_all(webapplet->viewer, TRUE); gtk_box_pack_start(GTK_BOX(webapplet->box), first_start(webapplet), FALSE, FALSE, 0); awn_applet_simple_set_tooltip_text(AWN_APPLET_SIMPLE(webapplet->applet), _("Web Applet")); } else { go_to_url(webapplet, (gchar*)config_get_uri(webapplet)); if (webapplet->sites_file) { const gchar *name = config_get_site(webapplet); if (name && strcmp(name, "") != 0) { gint size = awn_applet_get_size(webapplet->applet); WebSite *site = get_site(webapplet, (gchar*)name); gchar *path = g_strdup_printf(APPLETSDIR"/webapplet/icons/%s", site->icon); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(path, size, size, NULL); awn_applet_simple_set_icon_pixbuf(AWN_APPLET_SIMPLE(site->webapplet->applet), pixbuf); if (site->width && site->height) { gtk_widget_set_size_request(GTK_WIDGET(site->webapplet->box), site->width, site->height); } } } } gtk_box_pack_start(GTK_BOX(webapplet->box), webapplet->viewer, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(webapplet->mainwindow), webapplet->box); }
static gboolean _show_location_dialog(GtkMenuItem *menuitem, WebApplet *webapplet) { GtkWidget *dialog, *entry, *hbox, *vbox, *home_img, *home_box; gint response; /* Make the dialog */ dialog = gtk_dialog_new_with_buttons(_("Open Location"), GTK_WINDOW(webapplet->mainwindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); webapplet->location_dialog = dialog; /* Entry and "URL:" label */ entry = gtk_entry_new(); g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(_send_dialog_response), dialog); hbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("URL:")), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); /* Checkbox: Set as _home page, with nice little Home icon */ home_img = gtk_image_new_from_stock(GTK_STOCK_HOME, GTK_ICON_SIZE_MENU); webapplet->check_home = gtk_check_button_new_with_mnemonic(_("Set as new _Home Page")); home_box = gtk_hbox_new(FALSE, 3); gtk_box_pack_start(GTK_BOX(home_box), home_img, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(home_box), webapplet->check_home, FALSE, FALSE, 0); /* Put everything together */ vbox = gtk_vbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), website_buttons(webapplet), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), home_box, FALSE, FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 6); gtk_widget_show_all(vbox); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, TRUE, TRUE, 0); response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_OK) { gchar *url = (gchar*)gtk_entry_get_text(GTK_ENTRY(entry)); /* Open the page */ go_to_url(webapplet, url); set_title(webapplet, url); /* User entered a URL, didn't choose a site */ awn_applet_simple_set_icon_name(AWN_APPLET_SIMPLE(webapplet->applet), ICON_NAME); config_set_site(webapplet, ""); } gtk_widget_destroy(dialog); return TRUE; }