commit 1592c5f427d0482101a04a53069b8c18420f8288 Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Tue Nov 30 23:06:20 2010 +0000
Convert info dialog into a view * More user-friendly that a dialog floating around that can quickly disappear behind the parent window plugins/info_display/Makefile.am | 4 +- plugins/info_display/info.c | 91 +------- plugins/info_display/info.h | 2 +- plugins/info_display/info_display.glade | 62 ----- plugins/info_display/info_display.ui | 2 +- plugins/info_display/infodlg.c | 322 ------------------------ plugins/info_display/infoview.c | 238 +++++++++++++++++ plugins/info_display/{infodlg.h => infoview.h} | 14 +- plugins/info_display/plugin.c | 13 +- plugins/info_display/plugin.h | 3 + 10 files changed, 266 insertions(+), 485 deletions(-) --- diff --git a/plugins/info_display/Makefile.am b/plugins/info_display/Makefile.am index 68b79a9..5222bb0 100644 --- a/plugins/info_display/Makefile.am +++ b/plugins/info_display/Makefile.am @@ -8,7 +8,7 @@ info_display_ui_DATA = $(plugin_name).ui # Plugin Glade file info_display_gladedir = $(gtkpod_glade_dir) -info_display_glade_DATA = $(plugin_name).glade +info_display_glade_DATA = # Plugin Icon file info_display_pixmapsdir = $(gtkpod_image_dir) @@ -27,7 +27,7 @@ plugin_LTLIBRARIES = libinfo_display.la # Plugin sources libinfo_display_la_SOURCES = plugin.c plugin.h \ info.c info.h \ - infodlg.c infodlg.h + infoview.c infoview.h libinfo_display_la_LDFLAGS = $(GTKPOD_PLUGIN_LDFLAGS) diff --git a/plugins/info_display/info.c b/plugins/info_display/info.c index eba0e2a..b56237e 100644 --- a/plugins/info_display/info.c +++ b/plugins/info_display/info.c @@ -37,7 +37,7 @@ #include <glade/glade.h> #include "plugin.h" #include "info.h" -#include "infodlg.h" +#include "infoview.h" #include "libgtkpod/gtkpod_app_iface.h" #include "libgtkpod/misc.h" #include "libgtkpod/misc_track.h" @@ -48,8 +48,6 @@ /* pointer to info window */ static GtkWidget *info_window = NULL; -GladeXML *info_xml; - /* lock for size related variables (used by child and parent) */ static GMutex *space_mutex = NULL; static gboolean space_uptodate = FALSE; @@ -159,56 +157,6 @@ void fill_in_info(GList *tl, guint32 *tracks, guint32 *playtime, gdouble *filesi } } -static void fill_label_uint(gchar *w_name, guint32 nr) { - GtkWidget *w; - - g_return_if_fail (info_window); - g_return_if_fail (w_name); - w = gtkpod_xml_get_widget(info_xml, w_name); - if (w) { - gchar *str = g_strdup_printf("%u", nr); - gtk_label_set_text(GTK_LABEL (w), str); - g_free(str); - } -} - -static void fill_label_time(gchar *w_name, guint32 secs) { - GtkWidget *w; - - g_return_if_fail (info_window); - g_return_if_fail (w_name); - w = gtkpod_xml_get_widget(info_xml, w_name); - if (w) { - gchar *str = g_strdup_printf("%u:%02u:%02u", secs / 3600, (secs % 3600) / 60, secs % 60); - gtk_label_set_text(GTK_LABEL (w), str); - g_free(str); - } -} - -static void fill_label_size(gchar *w_name, gdouble size) { - GtkWidget *w; - - g_return_if_fail (info_window); - g_return_if_fail (w_name); - w = gtkpod_xml_get_widget(info_xml, w_name); - if (w) { - gchar *str = get_filesize_as_string(size); - gtk_label_set_text(GTK_LABEL (w), str); - g_free(str); - } -} - -static void fill_label_string(gchar *w_name, const char *str) { - GtkWidget *w; - - g_return_if_fail (info_window); - g_return_if_fail (w_name); - w = gtkpod_xml_get_widget(info_xml, w_name); - if (w) { - gtk_label_set_text(GTK_LABEL (w), str); - } -} - /* update all sections of info window */ void info_update(void) { callback_call_all(callbacks_info_update); @@ -227,9 +175,6 @@ static void info_update_track_view_displayed(void) { return; /* not open */ displayed = gtkpod_get_displayed_tracks(); fill_in_info(displayed, &tracks, &playtime, &filesize); - fill_label_uint("tracks_displayed", tracks); - fill_label_time("playtime_displayed", playtime); - fill_label_size("filesize_displayed", filesize); } static void info_update_track_view_selected(void) { @@ -242,9 +187,6 @@ static void info_update_track_view_selected(void) { selected = gtkpod_get_selected_tracks(); fill_in_info(selected, &tracks, &playtime, &filesize); g_list_free(selected); - fill_label_uint("tracks_selected", tracks); - fill_label_time("playtime_selected", playtime); - fill_label_size("filesize_selected", filesize); } /* update track view section */ @@ -272,9 +214,6 @@ void info_update_playlist_view(void) { return; tl = pl->members; fill_in_info(tl, &tracks, &playtime, &filesize); - fill_label_uint("playlist_tracks", tracks); - fill_label_time("playlist_playtime", playtime); - fill_label_size("playlist_filesize", filesize); } /* Get the local itdb */ @@ -326,23 +265,7 @@ static void info_update_totals_view_space(void) { itdb = get_itdb_ipod(); if (itdb) { gp_info_nontransferred_tracks(itdb, &nt_filesize, &nt_tracks); - fill_label_uint("non_transferred_tracks", nt_tracks); - fill_label_size("non_transferred_filesize", nt_filesize); gp_info_deleted_tracks(itdb, &del_filesize, &del_tracks); - fill_label_uint("deleted_tracks", del_tracks); - fill_label_size("deleted_filesize", del_filesize); - if (!get_offline(itdb)) { - if (ipod_connected()) { - gdouble free_space = get_ipod_free_space() + del_filesize - nt_filesize; - fill_label_size("free_space", free_space); - } - else { - fill_label_string("free_space", _("n/c")); - } - } - else { - fill_label_string("free_space", _("offline")); - } } } @@ -363,20 +286,12 @@ void info_update_totals_view(void) { pl = itdb_playlist_mpl(itdb); g_return_if_fail (pl); fill_in_info(pl->members, &tracks, &playtime, &filesize); - fill_label_uint("total_playlists_ipod", itdb_playlists_number(itdb) - 1); - fill_label_uint("total_tracks_ipod", tracks); - fill_label_time("total_playtime_ipod", playtime); - fill_label_size("total_filesize_ipod", filesize); } itdb = get_itdb_local(); if (itdb) { pl = itdb_playlist_mpl(itdb); g_return_if_fail (pl); fill_in_info(pl->members, &tracks, &playtime, &filesize); - fill_label_uint("total_playlists_local", itdb_playlists_number(itdb) - 1); - fill_label_uint("total_tracks_local", tracks); - fill_label_time("total_playtime_local", playtime); - fill_label_size("total_filesize_local", filesize); } info_update_totals_view_space(); } @@ -475,8 +390,8 @@ get_filesize_as_string(gdouble size) { } /* Action Callbacks */ -void on_info_window_open(GtkAction *action, InfoDisplayPlugin* plugin) { - open_info_dialog(); +void on_info_view_open(GtkAction *action, InfoDisplayPlugin* plugin) { + open_info_view(); } /* Selection Callbacks */ diff --git a/plugins/info_display/info.h b/plugins/info_display/info.h index c061ca1..87a3c76 100644 --- a/plugins/info_display/info.h +++ b/plugins/info_display/info.h @@ -66,7 +66,7 @@ void info_update_totals_view (void); gboolean ipod_connected (void); -void on_info_window_open (GtkAction *action, InfoDisplayPlugin* plugin); +void on_info_view_open (GtkAction *action, InfoDisplayPlugin* plugin); void info_display_playlist_selected_cb(GtkPodApp *app, gpointer pl, gpointer data); void info_display_playlist_added_cb(GtkPodApp *app, gpointer pl, gint32 pos, gpointer data); diff --git a/plugins/info_display/info_display.ui b/plugins/info_display/info_display.ui index 3a93f0d..36fa5ef 100644 --- a/plugins/info_display/info_display.ui +++ b/plugins/info_display/info_display.ui @@ -4,7 +4,7 @@ <menu name="MenuView" action="ActionMenuView"> <placeholder name="PlaceholderViewMenus"> <separator/> - <menuitem name="Info Window" action="ActionDisplayInfoWindow" /> + <menuitem name="Info Window" action="ActionDisplayInfoView" /> <separator/> </placeholder> </menu> diff --git a/plugins/info_display/infoview.c b/plugins/info_display/infoview.c new file mode 100644 index 0000000..1639dda --- /dev/null +++ b/plugins/info_display/infoview.c @@ -0,0 +1,238 @@ +/* + | Copyright (C) 2007 Maia Kozheva <sikon at users sourceforge net> + | Part of the gtkpod project. + | + | URL: http://www.gtkpod.org/ + | URL: http://gtkpod.sourceforge.net/ + | + | 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 + | (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY 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 with this program; if not, write to the Free Software + | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + | + | iTunes and iPod are trademarks of Apple + | + | This product is not supported/written/published by Apple! + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <glib.h> +#include <gtk/gtk.h> +#include "infoview.h" +#include "plugin.h" +#include "info.h" +#include "libgtkpod/misc.h" +#include "libgtkpod/prefs.h" +#include "libgtkpod/misc_track.h" +#include "libgtkpod/directories.h" + +const gchar *glade_file_path; + +enum info_view_columns { + C_DESCRIPTION = 0, C_TOTAL_IPOD, C_TOTAL_LOCAL, C_SELECTED_PLAYLIST, C_DISPLAYED_TRACKS, C_SELECTED_TRACKS, C_COUNT +}; + +static const gchar *column_headers[] = + { + "", N_("Total\n(iPod)"), N_("Total\n(local)"), N_("Selected\nPlaylist"), N_("Displayed\nTracks"), + N_("Selected\nTracks"), NULL }; + +enum info_view_rows { + R_NUMBER_OF_TRACKS, R_PLAY_TIME, R_FILE_SIZE, R_NUMBER_OF_PLAYLISTS, R_DELETED_TRACKS, R_FILE_SIZE_DELETED, R_NON_TRANSFERRED_TRACKS, R_FILE_SIZE_NON_TRANSFERRED, R_EFFECTIVE_FREE_SPACE, R_COUNT +}; + +static const gchar *row_headers[] = + { + N_("Number of tracks"), N_("Play time"), N_("File size"), N_("Number of playlists"), N_("Deleted tracks"), + N_("File size (deleted)"), N_("Non-transferred tracks"), N_("File size (non-transferred)"), + N_("Effective free space"), NULL }; + +static InfoView *info_view = NULL; + +static void info_view_set_text(gint row, gint column, const gchar *text) { + GtkTreeIter iter; + + gtk_tree_model_iter_nth_child(GTK_TREE_MODEL (info_view->store), &iter, NULL, row); + gtk_list_store_set(info_view->store, &iter, column, text, -1); +} + +static void info_view_set_uint(gint row, gint column, guint32 value) { + gchar buf[10]; + sprintf(buf, "%u", value); + info_view_set_text(row, column, buf); +} + +static void info_view_set_time(gint row, gint column, guint32 secs) { + gchar *str = g_strdup_printf("%u:%02u:%02u", secs / 3600, (secs % 3600) / 60, secs % 60); + + info_view_set_text(row, column, str); + g_free(str); +} + +static void info_view_set_size(gint row, gint column, gdouble size) { + gchar *str = get_filesize_as_string(size); + info_view_set_text(row, column, str); + g_free(str); +} + +static void update_view_generic(gint column, GList *list) { + guint32 tracks, playtime; /* playtime in secs */ + gdouble filesize; /* in bytes */ + + g_return_if_fail (info_view); + fill_in_info(list, &tracks, &playtime, &filesize); + info_view_set_uint(R_NUMBER_OF_TRACKS, column, tracks); + info_view_set_time(R_PLAY_TIME, column, playtime); + info_view_set_size(R_FILE_SIZE, column, filesize); +} + +static void on_info_view_update_track_view() { + update_view_generic(C_DISPLAYED_TRACKS, gtkpod_get_displayed_tracks()); + + update_view_generic(C_SELECTED_TRACKS, gtkpod_get_selected_tracks()); +} + +static void on_info_view_update_playlist_view() { + Playlist *pl = gtkpod_get_current_playlist(); + if (!pl) + return; + update_view_generic(C_SELECTED_PLAYLIST, pl->members); + +} + +static void on_info_view_update_totals_view() { + Playlist *pl; + iTunesDB *itdb; + gdouble nt_filesize, del_filesize; + guint32 nt_tracks, del_tracks; + + itdb = get_itdb_ipod(); + + if (itdb) { + pl = itdb_playlist_mpl(itdb); + g_return_if_fail (pl); + update_view_generic(C_TOTAL_IPOD, pl->members); + + info_view_set_uint(R_NUMBER_OF_PLAYLISTS, C_TOTAL_IPOD, itdb_playlists_number(itdb) - 1); + + gp_info_nontransferred_tracks(itdb, &nt_filesize, &nt_tracks); + gp_info_deleted_tracks(itdb, &del_filesize, &del_tracks); + + info_view_set_uint(R_NON_TRANSFERRED_TRACKS, C_TOTAL_IPOD, nt_tracks); + info_view_set_size(R_FILE_SIZE_NON_TRANSFERRED, C_TOTAL_IPOD, nt_filesize); + info_view_set_uint(R_DELETED_TRACKS, C_TOTAL_IPOD, del_tracks); + info_view_set_size(R_FILE_SIZE_DELETED, C_TOTAL_IPOD, del_filesize); + + if (!get_offline(itdb)) { + if (ipod_connected()) { + gdouble free_space = get_ipod_free_space() + del_filesize - nt_filesize; + info_view_set_size(R_EFFECTIVE_FREE_SPACE, C_TOTAL_IPOD, free_space); + } + else + info_view_set_text(R_EFFECTIVE_FREE_SPACE, C_TOTAL_IPOD, _("n/c")); + } + else + info_view_set_text(R_EFFECTIVE_FREE_SPACE, C_TOTAL_IPOD, _("offline")); + } + + itdb = get_itdb_local(); + + if (itdb) { + pl = itdb_playlist_mpl(itdb); + g_return_if_fail (pl); + update_view_generic(C_TOTAL_LOCAL, pl->members); + + info_view_set_uint(R_NUMBER_OF_PLAYLISTS, C_TOTAL_LOCAL, itdb_playlists_number(itdb) - 1); + } +} + +static void setup_info_view() { + gint i; + + info_view->store + = gtk_list_store_new(C_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + + for (i = 0; column_headers[i]; i++) { + const gchar *hdr = column_headers[i][0] ? _(column_headers[i]) : column_headers[i]; + GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); + + g_object_set(renderer, "editable", i > 0, "foreground", i % 2 ? "#000000" : "#000000", NULL); + + gtk_tree_view_insert_column_with_attributes(info_view->tree, -1, hdr, renderer, "markup", i, NULL); + } + + for (i = 0; row_headers[i]; i++) { + GtkTreeIter iter; + gchar *text = g_strdup_printf("<b>%s</b>", _(row_headers[i])); + + gtk_list_store_append(info_view->store, &iter); + gtk_list_store_set(info_view->store, &iter, C_DESCRIPTION, text, -1); + g_free(text); + } + + gtk_tree_view_set_model(info_view->tree, GTK_TREE_MODEL (info_view->store)); + g_object_unref(info_view->store); + + register_info_update_track_view(on_info_view_update_track_view); + register_info_update_playlist_view(on_info_view_update_playlist_view); + register_info_update_totals_view(on_info_view_update_totals_view); + info_update(); +} + +static void create_info_view() { + info_view = g_malloc0(sizeof(InfoView)); + + /* Add widget in Shell. */ + info_display_plugin->info_window = gtk_scrolled_window_new(NULL, NULL); + g_object_ref(info_display_plugin->info_window); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (info_display_plugin->info_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (info_display_plugin->info_window), GTK_SHADOW_IN); + info_view->window = info_display_plugin->info_window; + + info_view->tree = GTK_TREE_VIEW (gtk_tree_view_new()); + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(info_view->window), GTK_WIDGET (info_view->tree)); + anjuta_shell_add_widget(ANJUTA_PLUGIN(info_display_plugin)->shell, info_view->window, "InfoDisplayPlugin", _(" Repository Information"), NULL, ANJUTA_SHELL_PLACEMENT_BOTTOM, NULL); + + setup_info_view(); +} + +void open_info_view() { + if (!info_view || !info_view->window) { + create_info_view(); + } + else if (!gtk_widget_get_realized(info_view->window)) { + gtkpod_display_widget(info_view->window); + } + + gtk_widget_show_all(info_view->window); +} + +void destroy_info_view() { + if (!info_view) + return; + + unregister_info_update_track_view(on_info_view_update_track_view); + unregister_info_update_playlist_view(on_info_view_update_playlist_view); + unregister_info_update_totals_view(on_info_view_update_totals_view); + + g_object_unref(info_view->store); + g_object_unref(info_view->tree); + + if (info_view->window) { + gtk_widget_destroy(info_view->window); + } + + g_free(info_view); +} diff --git a/plugins/info_display/infodlg.h b/plugins/info_display/infoview.h similarity index 82% rename from plugins/info_display/infodlg.h rename to plugins/info_display/infoview.h index b0a3a8a..dcaba7d 100644 --- a/plugins/info_display/infodlg.h +++ b/plugins/info_display/infoview.h @@ -27,8 +27,16 @@ #ifndef __INFODLG_H__ #define __INFODLG_H__ -void open_info_dialog (); -void close_info_dialog (); -void info_dialog_update_default_sizes (); +struct _InfoView +{ + GtkWidget *window; /* pointer to info window */ + GtkTreeView *tree; + GtkListStore *store; +}; + +typedef struct _InfoView InfoView; + +void open_info_view (); +void destroy_info_view (); #endif diff --git a/plugins/info_display/plugin.c b/plugins/info_display/plugin.c index cd968a8..49e57e1 100644 --- a/plugins/info_display/plugin.c +++ b/plugins/info_display/plugin.c @@ -35,6 +35,7 @@ #include "libgtkpod/directories.h" #include "plugin.h" #include "info.h" +#include "infoview.h" /* Parent class. Part of standard class definition */ static gpointer parent_class; @@ -42,18 +43,17 @@ static gpointer parent_class; static GtkActionEntry info_actions[] = { { - "ActionDisplayInfoWindow", /* Action name */ + "ActionDisplayInfoView", /* Action name */ GTK_STOCK_DIALOG_INFO, /* Stock icon */ - N_("_Info Window"), /* Display label */ + N_("_Info View"), /* Display label */ NULL, /* short-cut */ NULL, /* Tooltip */ - G_CALLBACK (on_info_window_open) /* callback */ + G_CALLBACK (on_info_view_open) /* callback */ }, }; static gboolean activate_plugin(AnjutaPlugin *plugin) { AnjutaUI *ui; - InfoDisplayPlugin *info_display_plugin; GtkActionGroup* action_group; info_display_plugin = (InfoDisplayPlugin*) plugin; @@ -65,7 +65,7 @@ static gboolean activate_plugin(AnjutaPlugin *plugin) { info_display_plugin->action_group = action_group; /* Merge UI */ - gchar *uipath = g_build_filename(get_ui_dir(), "details_editor.ui", NULL); + gchar *uipath = g_build_filename(get_ui_dir(), "info_display.ui", NULL); info_display_plugin->uiid = anjuta_ui_merge(ui, uipath); g_free(uipath); @@ -86,7 +86,8 @@ static gboolean activate_plugin(AnjutaPlugin *plugin) { static gboolean deactivate_plugin(AnjutaPlugin *plugin) { AnjutaUI *ui; - InfoDisplayPlugin *info_display_plugin; + + destroy_info_view (); info_display_plugin = (InfoDisplayPlugin*) plugin; ui = anjuta_shell_get_ui(plugin->shell, NULL); diff --git a/plugins/info_display/plugin.h b/plugins/info_display/plugin.h index e4bcf97..c539ca2 100644 --- a/plugins/info_display/plugin.h +++ b/plugins/info_display/plugin.h @@ -43,10 +43,13 @@ struct _InfoDisplayPlugin { AnjutaPlugin parent; gint uiid; GtkActionGroup *action_group; + GtkWidget *info_window; }; struct _InfoDisplayPluginClass { AnjutaPluginClass parent_class; }; +InfoDisplayPlugin *info_display_plugin; + #endif /* PLUGIN_H_ */ ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2