*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
#ifdef HAVE_CONFIG_H
#include <stdarg.h>
#include <sys/stat.h>
+#include "combobox.h"
+
#if HAVE_LIBCOMPFACE
# include <compface.h>
#endif
#include "manage_window.h"
#include "base64.h"
#include "manual.h"
+#include "combobox.h"
gboolean gtkut_get_font_size(GtkWidget *widget,
gint *width, gint *height)
gtk_button_box_set_child_secondary(GTK_BUTTON_BOX (bbox),
*help_btn, TRUE);
gtk_widget_set_sensitive(*help_btn,
- manual_available(MANUAL_MANUAL_LOCAL));
+ manual_available(MANUAL_MANUAL_CLAWS));
gtk_widget_show(*help_btn);
}
if (new_x != x || new_y != y)
gdk_window_move(window->window, new_x, new_y);
+ gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), FALSE);
+#if GTK_CHECK_VERSION(2,8,0)
+ gtk_window_present_with_time(GTK_WINDOW(window), time(NULL));
+#else
gtk_window_present(GTK_WINDOW(window));
+#endif
}
void gtkut_widget_get_uposition(GtkWidget *widget, gint *px, gint *py)
void gtkut_widget_draw_now(GtkWidget *widget)
{
- if (GTK_WIDGET_VISIBLE(widget) && GTK_WIDGET_DRAWABLE(widget))
+ if (widget && GTK_WIDGET_VISIBLE(widget) && GTK_WIDGET_DRAWABLE(widget))
gdk_window_process_updates(widget->window, FALSE);
}
gdk_window_set_icon(widget->window, NULL, xpm, bmp);
}
+static gboolean move_bar = FALSE;
+static gint move_bar_id = -1;
+
+static gboolean move_bar_cb(gpointer data)
+{
+ GtkWidget *w = (GtkWidget *)data;
+ if (!move_bar)
+ return FALSE;
+
+ if (!GTK_IS_PROGRESS_BAR(w)) {
+ return FALSE;
+ }
+
+ gtk_progress_bar_pulse(GTK_PROGRESS_BAR(w));
+ GTK_EVENTS_FLUSH();
+ return TRUE;
+}
+
GtkWidget *label_window_create(const gchar *str)
{
GtkWidget *window;
- GtkWidget *label;
+ GtkWidget *label, *vbox, *hbox;
+ GtkWidget *wait_progress = gtk_progress_bar_new();
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_widget_set_size_request(window, 380, 60);
+ window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "gtkutils");
+ gtk_widget_set_size_request(window, 380, 70);
gtk_container_set_border_width(GTK_CONTAINER(window), 8);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), str);
manage_window_set_transient(GTK_WINDOW(window));
label = gtk_label_new(str);
- gtk_container_add(GTK_CONTAINER(window), label);
+
+ vbox = gtk_vbox_new(FALSE, 6);
+ hbox = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 0);
+ hbox = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(hbox), wait_progress, TRUE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+ gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_widget_show(label);
+ gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
+ gtk_widget_show_all(vbox);
gtk_widget_show_now(window);
+ if (move_bar_id == -1) {
+ move_bar_id = g_timeout_add(200, move_bar_cb, wait_progress);
+ move_bar = TRUE;
+ }
+
GTK_EVENTS_FLUSH();
return window;
}
+void label_window_destroy(GtkWidget *window)
+{
+ move_bar = FALSE;
+ g_source_remove(move_bar_id);
+ move_bar_id = -1;
+ GTK_EVENTS_FLUSH();
+ gtk_widget_destroy(window);
+}
+
GtkWidget *gtkut_account_menu_new(GList *ac_list,
- GCallback callback,
- gpointer data)
+ GCallback callback,
+ gpointer data)
{
GList *cur_ac;
- GtkWidget *menu;
+ GtkWidget *optmenu;
+ GtkListStore *menu;
+ GtkTreeIter iter;
+ PrefsAccount *account;
+ gchar *name;
g_return_val_if_fail(ac_list != NULL, NULL);
- menu = gtk_menu_new();
+ optmenu = gtkut_sc_combobox_create(NULL, FALSE);
+ menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
for (cur_ac = ac_list; cur_ac != NULL; cur_ac = cur_ac->next) {
- gchar *name;
- GtkWidget *menuitem;
- PrefsAccount *account;
-
account = (PrefsAccount *) cur_ac->data;
if (account->name)
name = g_strdup_printf("%s: %s <%s>",
name = g_strdup_printf("%s: %s",
account->account_name,
account->address);
- MENUITEM_ADD(menu, menuitem, name, account->account_id);
+ COMBOBOX_ADD_ESCAPED(menu, name, account->account_id);
g_free(name);
- if (callback != NULL)
- g_signal_connect(G_OBJECT(menuitem), "activate",
- callback, data);
}
- return menu;
+ gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
+
+ if( callback != NULL )
+ g_signal_connect(G_OBJECT(optmenu), "changed", callback, data);
+
+ return optmenu;
}
void gtkut_set_widget_bgcolor_rgb(GtkWidget *widget, guint rgbvalue)
return button;
}
+/**
+ * merge some part of code into one function : it creates a frame and add
+ * these into gtk box widget passed in param.
+ * \param box gtk box where adding new created frame.
+ * \param pframe pointer with which to assign the frame. If NULL, no pointer
+ * is assigned but the frame is anyway created and added to @box.
+ * \param frame_label frame label of new created frame.
+ */
+GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **pframe,
+ const gchar *frame_label)
+{
+ GtkWidget *vbox;
+ GtkWidget *frame;
+
+ frame = gtk_frame_new(frame_label);
+ gtk_widget_show(frame);
+ gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
+ gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5);
+
+ vbox = gtk_vbox_new (FALSE, 4);
+ gtk_widget_show(vbox);
+ gtk_container_add(GTK_CONTAINER (frame), vbox);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+
+ if (pframe != NULL)
+ *pframe = frame;
+
+ return vbox;
+}
+
#if HAVE_LIBCOMPFACE
-gint create_xpm_from_xface(gchar *xpm[], const gchar *xface)
+static gint create_xpm_from_xface(gchar *xpm[], const gchar *xface)
{
static gchar *bit_pattern[] = {
"....",
pixmap = gdk_pixmap_create_from_xpm_d
(window, &mask,
background, xpm_xface);
- return gtk_image_new_from_pixmap(pixmap, mask);
+ return gtk_image_new_from_pixbuf(
+ gdk_pixbuf_new_from_xpm_data((const char **)xpm_xface));
}
#endif
return btn;
}
+static gboolean _combobox_separator_func(GtkTreeModel *model,
+ GtkTreeIter *iter, gpointer data)
+{
+ gchar *txt = NULL;
+
+ g_return_val_if_fail(model != NULL, FALSE);
+
+ gtk_tree_model_get(model, iter, COMBOBOX_TEXT, &txt, -1);
+
+ if( txt == NULL )
+ return TRUE;
+ return FALSE;
+}
+
GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click)
{
GtkWidget *combobox;
GtkListStore *menu;
GtkCellRenderer *rend;
- menu = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
+ menu = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(menu));
rend = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), rend, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox), rend,
- "markup", 0,
+ "markup", COMBOBOX_TEXT,
+ "sensitive", COMBOBOX_SENS,
NULL);
if( eventbox != NULL )
#if GTK_CHECK_VERSION(2,6,0)
gtk_combo_box_set_focus_on_click(GTK_COMBO_BOX(combobox), focus_on_click);
#endif
+
+ gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combobox),
+ (GtkTreeViewRowSeparatorFunc)_combobox_separator_func, NULL, NULL);
+
return combobox;
}
return gtk_tree_model_iter_nth_child(model, iter, NULL, count - 1);
}
+
+GtkWidget *gtkut_window_new (GtkWindowType type,
+ const gchar *class)
+{
+#ifndef MAEMO
+ GtkWidget *window = gtk_window_new(type);
+#else
+ GtkWidget *window = hildon_window_new();
+ hildon_program_add_window(hildon_program, HILDON_WINDOW(window));
+#endif
+ gtk_window_set_role(GTK_WINDOW(window), class);
+ return window;
+}
+
+gboolean gtkut_tree_iter_comp(GtkTreeModel *model,
+ GtkTreeIter *iter1,
+ GtkTreeIter *iter2)
+{
+ GtkTreePath *path1 = gtk_tree_model_get_path(model, iter1);
+ GtkTreePath *path2 = gtk_tree_model_get_path(model, iter2);
+ gboolean result;
+
+ result = gtk_tree_path_compare(path1, path2) == 0;
+
+ gtk_tree_path_free(path1);
+ gtk_tree_path_free(path2);
+
+ return result;
+}
+
+/*!
+ *\brief Get selected row number.
+ */
+gint gtkut_list_view_get_selected_row(GtkWidget *list_view)
+{
+ GtkTreeView *view = GTK_TREE_VIEW(list_view);
+ GtkTreeModel *model = gtk_tree_view_get_model(view);
+ int n_rows = gtk_tree_model_iter_n_children(model, NULL);
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ int row;
+
+ if (n_rows == 0)
+ return -1;
+
+ selection = gtk_tree_view_get_selection(view);
+ if (!gtk_tree_selection_get_selected(selection, &model, &iter))
+ return -1;
+
+ /* get all iterators and compare them... */
+ for (row = 0; row < n_rows; row++) {
+ GtkTreeIter itern;
+
+ gtk_tree_model_iter_nth_child(model, &itern, NULL, row);
+ if (gtkut_tree_iter_comp(model, &iter, &itern))
+ return row;
+ }
+
+ return -1;
+}
+
+/*!
+ *\brief Select a row by its number.
+ */
+gboolean gtkut_list_view_select_row(GtkWidget *list, gint row)
+{
+ GtkTreeView *list_view = GTK_TREE_VIEW(list);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
+ GtkTreeModel *model = gtk_tree_view_get_model(list_view);
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
+ return FALSE;
+
+ gtk_tree_selection_select_iter(selection, &iter);
+
+ path = gtk_tree_model_get_path(model, &iter);
+ gtk_tree_view_set_cursor(list_view, path, NULL, FALSE);
+ gtk_tree_path_free(path);
+
+ return TRUE;
+}
+