]> spindle.queued.net Git - midori/commitdiff
Cleanup sokoke
authorChristian Dywan <christian@twotoasts.de>
Sun, 1 Jun 2008 15:39:57 +0000 (17:39 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 1 Jun 2008 15:39:57 +0000 (17:39 +0200)
src/sokoke.c
src/sokoke.h

index d22c1371aa4c16354c523f51c35abdcf76d9e1ef..157252d5f6f549c4a97aa7d4a5921ef7089760d7 100644 (file)
@@ -98,59 +98,66 @@ sokoke_entry_append_completion (GtkEntry* entry, const gchar* text)
     gtk_list_store_set (GTK_LIST_STORE (completion_store), &iter, 0, text, -1);
 }
 
-void sokoke_combo_box_add_strings(GtkComboBox* combobox
- , const gchar* labelFirst, ...)
+void
+sokoke_combo_box_add_strings (GtkComboBox* combobox,
+                              const gchar* label_first, ...)
 {
     // Add a number of strings to a combobox, terminated with NULL
     // This works only for text comboboxes
     va_list args;
-    va_start(args, labelFirst);
+    va_start (args, label_first);
 
     const gchar* label;
-    for(label = labelFirst; label; label = va_arg(args, const gchar*))
-        gtk_combo_box_append_text(combobox, label);
+    for (label = label_first; label; label = va_arg (args, const gchar*))
+        gtk_combo_box_append_text (combobox, label);
 
-    va_end(args);
+    va_end (args);
 }
 
-void sokoke_widget_set_visible(GtkWidget* widget, gboolean visible)
+void sokoke_widget_set_visible (GtkWidget* widget, gboolean visible)
 {
     // Show or hide the widget
-    if(visible)
-        gtk_widget_show(widget);
+    if (visible)
+        gtk_widget_show (widget);
     else
-        gtk_widget_hide(widget);
+        gtk_widget_hide (widget);
 }
 
-void sokoke_container_show_children(GtkContainer* container)
+void
+sokoke_container_show_children (GtkContainer* container)
 {
     // Show every child but not the container itself
-    gtk_container_foreach(container, (GtkCallback)(gtk_widget_show_all), NULL);
+    gtk_container_foreach (container, (GtkCallback)(gtk_widget_show_all), NULL);
 }
 
-void sokoke_widget_set_tooltip_text(GtkWidget* widget, const gchar* text)
+void
+sokoke_widget_set_tooltip_text (GtkWidget* widget, const gchar* text)
 {
     #if GTK_CHECK_VERSION(2, 12, 0)
-    gtk_widget_set_tooltip_text(widget, text);
+    gtk_widget_set_tooltip_text (widget, text);
     #else
     static GtkTooltips* tooltips;
-    if(!tooltips)
-        tooltips = gtk_tooltips_new();
-    gtk_tooltips_set_tip(tooltips, widget, text, NULL);
+    if (!tooltips)
+        tooltips = gtk_tooltips_new ();
+    gtk_tooltips_set_tip (tooltips, widget, text, NULL);
     #endif
 }
 
 void
 sokoke_tool_item_set_tooltip_text (GtkToolItem* toolitem, const gchar* text)
 {
-    // TODO: Use 2.12 api if available
-    static GtkTooltips* tooltips = NULL;
-
-    if (G_UNLIKELY (!tooltips))
-        tooltips = gtk_tooltips_new();
-
     if (text && *text)
+    {
+        #if GTK_CHECK_VERSION(2, 12, 0)
+        gtk_tool_item_set_tooltip_text (toolitem, text);
+        #else
+        static GtkTooltips* tooltips = NULL;
+        if (G_UNLIKELY (!tooltips))
+            tooltips = gtk_tooltips_new();
+
         gtk_tool_item_set_tooltip (toolitem, tooltips, text, NULL);
+        #endif
+    }
 }
 
 typedef struct
@@ -243,17 +250,18 @@ typedef enum
     SOKOKE_DESKTOP_UNKNOWN
 } SokokeDesktop;
 
-static SokokeDesktop sokoke_get_desktop(void)
+static SokokeDesktop
+sokoke_get_desktop (void)
 {
     static SokokeDesktop desktop = SOKOKE_DESKTOP_UNTESTED;
-    if(G_UNLIKELY(desktop == SOKOKE_DESKTOP_UNTESTED))
+    if (G_UNLIKELY (desktop == SOKOKE_DESKTOP_UNTESTED))
     {
         // Are we running in Xfce?
         gint result; gchar* out; gchar* err;
-        gboolean success = g_spawn_command_line_sync(
-         "xprop -root _DT_SAVE_MODE | grep -q xfce4"
-         , &out, &err, &result, NULL);
-        if(success && !result)
+        gboolean success = g_spawn_command_line_sync (
+            "xprop -root _DT_SAVE_MODE | grep -q xfce4",
+            &out, &err, &result, NULL);
+        if (success && !result)
             desktop = SOKOKE_DESKTOP_XFCE;
         else
             desktop = SOKOKE_DESKTOP_UNKNOWN;
@@ -262,35 +270,39 @@ static SokokeDesktop sokoke_get_desktop(void)
     return desktop;
 }
 
-gpointer sokoke_xfce_header_new(const gchar* icon, const gchar* title)
+GtkWidget*
+sokoke_xfce_header_new (const gchar* icon,
+                        const gchar* title)
 {
     // Create an xfce header with icon and title
     // This returns NULL if the desktop is not xfce
-    if(sokoke_get_desktop() == SOKOKE_DESKTOP_XFCE)
+    if (sokoke_get_desktop () == SOKOKE_DESKTOP_XFCE)
     {
-        GtkWidget* entry = gtk_entry_new();
+        GtkWidget* entry = gtk_entry_new ();
         gchar* markup;
-        GtkWidget* xfce_heading = gtk_event_box_new();
-        gtk_widget_modify_bg(xfce_heading, GTK_STATE_NORMAL
-         , &entry->style->base[GTK_STATE_NORMAL]);
-        GtkWidget* hbox = gtk_hbox_new(FALSE, 12);
-        gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
-        GtkWidget* image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_DIALOG);
-        gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
-        GtkWidget* label = gtk_label_new(NULL);
-        gtk_widget_modify_fg(label, GTK_STATE_NORMAL
+        GtkWidget* xfce_heading = gtk_event_box_new ();
+        gtk_widget_modify_bg (xfce_heading, GTK_STATE_NORMAL,
+            &entry->style->base[GTK_STATE_NORMAL]);
+        GtkWidget* hbox = gtk_hbox_new (FALSE, 12);
+        gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
+        GtkWidget* image = gtk_image_new_from_icon_name (icon,
+                                                         GTK_ICON_SIZE_DIALOG);
+        gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+        GtkWidget* label = gtk_label_new (NULL);
+        gtk_widget_modify_fg (label, GTK_STATE_NORMAL
          , &entry->style->text[GTK_STATE_NORMAL]);
-        markup = g_strdup_printf("<span size='large' weight='bold'>%s</span>", title);
-        gtk_label_set_markup(GTK_LABEL(label), markup);
-        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-        gtk_container_add(GTK_CONTAINER(xfce_heading), hbox);
-        g_free(markup);
+        markup = g_strdup_printf ("<span size='large' weight='bold'>%s</span>",
+                                  title);
+        gtk_label_set_markup (GTK_LABEL (label), markup);
+        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+        gtk_container_add (GTK_CONTAINER (xfce_heading), hbox);
+        g_free (markup);
         return xfce_heading;
     }
     return NULL;
 }
 
-gpointer
+GtkWidget*
 sokoke_superuser_warning_new (void)
 {
     // Create a horizontal bar with a security warning
@@ -315,31 +327,34 @@ sokoke_superuser_warning_new (void)
     return NULL;
 }
 
-GtkWidget* sokoke_hig_frame_new(const gchar* title)
+GtkWidget*
+sokoke_hig_frame_new (const gchar* title)
 {
     // Create a frame with no actual frame but a bold label and indentation
-    GtkWidget* frame = gtk_frame_new(NULL);
-    gchar* titleBold = g_strdup_printf("<b>%s</b>", title);
-    GtkWidget* label = gtk_label_new(NULL);
-    gtk_label_set_markup(GTK_LABEL(label), titleBold);
-    g_free(titleBold);
-    gtk_frame_set_label_widget(GTK_FRAME(frame), label);
-    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
+    GtkWidget* frame = gtk_frame_new (NULL);
+    gchar* title_bold = g_strdup_printf ("<b>%s</b>", title);
+    GtkWidget* label = gtk_label_new (NULL);
+    gtk_label_set_markup (GTK_LABEL (label), title_bold);
+    g_free (title_bold);
+    gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+    gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
     return frame;
 }
 
-void sokoke_widget_set_pango_font_style(GtkWidget* widget, PangoStyle style)
+void
+sokoke_widget_set_pango_font_style (GtkWidget* widget,
+                                    PangoStyle style)
 {
     // Conveniently change the pango font style
     // For some reason we need to reset if we actually want the normal style
-    if(style == PANGO_STYLE_NORMAL)
-        gtk_widget_modify_font(widget, NULL);
+    if (style == PANGO_STYLE_NORMAL)
+        gtk_widget_modify_font (widget, NULL);
     else
     {
-        PangoFontDescription* fontDescription = pango_font_description_new();
-        pango_font_description_set_style(fontDescription, PANGO_STYLE_ITALIC);
-        gtk_widget_modify_font(widget, fontDescription);
-        pango_font_description_free(fontDescription);
+        PangoFontDescription* font_description = pango_font_description_new ();
+        pango_font_description_set_style (font_description, PANGO_STYLE_ITALIC);
+        gtk_widget_modify_font (widget, font_description);
+        pango_font_description_free (font_description);
     }
 }
 
@@ -374,7 +389,7 @@ sokoke_on_entry_focus_out_event (GtkEntry*      entry,
         gtk_entry_set_text (entry, defaultText);
         g_object_set_data (G_OBJECT(entry),
                            "sokoke_has_default", GINT_TO_POINTER (1));
-        sokoke_widget_set_pango_font_style (GTK_WIDGET(entry),
+        sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
                                             PANGO_STYLE_ITALIC);
     }
     return FALSE;
@@ -403,19 +418,27 @@ sokoke_entry_set_default_text (GtkEntry*    entry,
         G_CALLBACK (sokoke_on_entry_focus_out_event), NULL);
 }
 
-gchar* sokoke_key_file_get_string_default(GKeyFile* keyFile
- , const gchar* group, const gchar* key, const gchar* defaultValue, GError** error)
+gchar*
+sokoke_key_file_get_string_default (GKeyFile*    key_file,
+                                    const gchar* group,
+                                    const gchar* key,
+                                    const gchar* default_value,
+                                    GError**     error)
 {
-    gchar* value = g_key_file_get_string(keyFile, group, key, error);
-    return value == NULL ? g_strdup(defaultValue) : value;
+    gchar* value = g_key_file_get_string (key_file, group, key, error);
+    return value == NULL ? g_strdup (default_value) : value;
 }
 
-gint sokoke_key_file_get_integer_default(GKeyFile* keyFile
- , const gchar* group, const gchar* key, const gint defaultValue, GError** error)
+gint
+sokoke_key_file_get_integer_default (GKeyFile*    key_file,
+                                     const gchar* group,
+                                     const gchar* key,
+                                     const gint   default_value,
+                                     GError**     error)
 {
-    if(!g_key_file_has_key(keyFile, group, key, NULL))
-        return defaultValue;
-    return g_key_file_get_integer(keyFile, group, key, error);
+    if (!g_key_file_has_key (key_file, group, key, NULL))
+        return default_value;
+    return g_key_file_get_integer (key_file, group, key, error);
 }
 
 gdouble
@@ -442,42 +465,34 @@ sokoke_key_file_get_boolean_default (GKeyFile*      key_file,
     return g_key_file_get_boolean (key_file, group, key, error);
 }
 
-gboolean sokoke_key_file_save_to_file(GKeyFile* keyFile
- , const gchar* filename, GError** error)
+gboolean
+sokoke_key_file_save_to_file (GKeyFile*    key_file,
+                              const gchar* filename,
+                              GError**     error)
 {
-    gchar* data = g_key_file_to_data(keyFile, NULL, error);
-    if(!data)
+    gchar* data = g_key_file_to_data (key_file, NULL, error);
+    if (!data)
         return FALSE;
     FILE* fp;
-    if(!(fp = fopen(filename, "w")))
+    if (!(fp = fopen (filename, "w")))
     {
-        *error = g_error_new(G_FILE_ERROR, G_FILE_ERROR_ACCES
-         , _("Writing failed."));
+        *error = g_error_new (G_FILE_ERROR, G_FILE_ERROR_ACCES,
+                              _("Writing failed."));
         return FALSE;
     }
-    fputs(data, fp);
-    fclose(fp);
-    g_free(data);
+    fputs (data, fp);
+    fclose (fp);
+    g_free (data);
     return TRUE;
 }
 
-void sokoke_widget_get_text_size(GtkWidget* widget, const gchar* text
- , gint* w, gint* h)
-{
-    PangoLayout* layout = gtk_widget_create_pango_layout(widget, text);
-    pango_layout_get_pixel_size(layout, w, h);
-    g_object_unref(layout);
-}
-
-void sokoke_menu_item_set_accel(GtkMenuItem* menuitem, const gchar* path
- , const gchar* key, GdkModifierType modifiers)
+void
+sokoke_widget_get_text_size (GtkWidget*   widget,
+                             const gchar* text,
+                             gint*        width,
+                             gint*        height)
 {
-    if(path && *path)
-    {
-        gchar* accel = g_strconcat("<", g_get_prgname(), ">/", path, NULL);
-        gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), accel);
-        guint keyVal = key ? gdk_keyval_from_name(key) : 0;
-        gtk_accel_map_add_entry(accel, keyVal, modifiers);
-        g_free(accel);
-    }
+    PangoLayout* layout = gtk_widget_create_pango_layout (widget, text);
+    pango_layout_get_pixel_size (layout, width, height);
+    g_object_unref (layout);
 }
index 26a504db26a8b39b8f8c2a403dda27edf2120e27..89e3ba2e6551a09a1fff71c1e5b186820567b642 100644 (file)
@@ -25,7 +25,7 @@ void
 sokoke_entry_setup_completion  (GtkEntry* entry);
 
 void
-sokoke_entry_append_completion (GtkEntry* entry,
+sokoke_entry_append_completion (GtkEntry*    entry,
                                 const gchar* text);
 
 typedef enum {
@@ -35,45 +35,60 @@ typedef enum {
 } SokokeMenuPos;
 
 void
-sokoke_combo_box_add_strings(GtkComboBox*, const gchar*, ...);
+sokoke_combo_box_add_strings (GtkComboBox* combobox,
+                              const gchar* label_first, ...);
 
 void
-sokoke_widget_set_visible(GtkWidget*, gboolean);
+sokoke_widget_set_visible (GtkWidget* widget,
+                           gboolean   visible);
 
 void
-sokoke_container_show_children(GtkContainer*);
+sokoke_container_show_children (GtkContainer* container);
 
 void
-sokoke_widget_set_tooltip_text(GtkWidget*, const gchar*);
+sokoke_widget_set_tooltip_text (GtkWidget*   widget,
+                                const gchar* text);
 
 void
-sokoke_tool_item_set_tooltip_text(GtkToolItem*, const gchar*);
+sokoke_tool_item_set_tooltip_text (GtkToolItem* toolitem,
+                                   const gchar* text);
 
 void
-sokoke_widget_popup(GtkWidget*, GtkMenu*, GdkEventButton*, SokokeMenuPos pos);
+sokoke_widget_popup (GtkWidget*      widget,
+                     GtkMenu*        menu,
+                     GdkEventButton* event,
+                     SokokeMenuPos   pos);
 
-gpointer
-sokoke_xfce_header_new(const gchar*, const gchar*);
+GtkWidget*
+sokoke_xfce_header_new (const gchar* icon,
+                        const gchar* title);
 
-gpointer
-sokoke_superuser_warning_new(void);
+GtkWidget*
+sokoke_superuser_warning_new (void);
 
 GtkWidget*
-sokoke_hig_frame_new(const gchar*);
+sokoke_hig_frame_new (const gchar* title);
 
 void
-sokoke_widget_set_pango_font_style(GtkWidget*, PangoStyle);
+sokoke_widget_set_pango_font_style (GtkWidget* widget,
+                                    PangoStyle style);
 
 void
 sokoke_entry_set_default_text(GtkEntry*, const gchar*);
 
 gchar*
-sokoke_key_file_get_string_default(GKeyFile*, const gchar*, const gchar*
- , const gchar*, GError**);
+sokoke_key_file_get_string_default (GKeyFile*    key_file,
+                                    const gchar* group,
+                                    const gchar* key,
+                                    const gchar* default_value,
+                                    GError**     error);
 
 gint
-sokoke_key_file_get_integer_default(GKeyFile*, const gchar*, const gchar*
- , const gint, GError**);
+sokoke_key_file_get_integer_default (GKeyFile*    key_file,
+                                     const gchar* group,
+                                     const gchar* key,
+                                     const gint   default_value,
+                                     GError**     error);
 
 gdouble
 sokoke_key_file_get_double_default (GKeyFile*    key_file,
@@ -90,12 +105,14 @@ sokoke_key_file_get_boolean_default (GKeyFile*    key_file,
                                      GError**     error);
 
 gboolean
-sokoke_key_file_save_to_file(GKeyFile*, const gchar*, GError**);
-
-void
-sokoke_widget_get_text_size(GtkWidget*, const gchar*, gint*, gint*);
+sokoke_key_file_save_to_file (GKeyFile*    key_file,
+                              const gchar* filename,
+                              GError**     error);
 
 void
-sokoke_menu_item_set_accel(GtkMenuItem*, const gchar*, const gchar*, GdkModifierType);
+sokoke_widget_get_text_size (GtkWidget*   widget,
+                             const gchar* text,
+                             gint*        width,
+                             gint*        height);
 
 #endif /* !__SOKOKE_H__ */