This is an automated email from the git hooks/post-receive script. peter pushed a commit to branch stephan/new-ui in repository apps/squeeze.
commit 0c4e85dea8df7c73c0eddac3abf2a37d910195ed Author: Peter de Ridder <pe...@xfce.org> Date: Sat Nov 1 23:43:05 2014 +0100 Open archive connected to the new ui --- libsqueeze/support-info.c | 2 +- src/archive_store.c | 411 ++++++++------------------ src/archive_store.h | 85 ++---- src/main.c | 3 - src/main_window.c | 715 ++++++++++++++++++++++++++++++--------------- src/main_window.h | 39 +-- src/main_window_ui.xml | 18 +- 7 files changed, 675 insertions(+), 598 deletions(-) diff --git a/libsqueeze/support-info.c b/libsqueeze/support-info.c index 74071eb..f923ba3 100644 --- a/libsqueeze/support-info.c +++ b/libsqueeze/support-info.c @@ -192,5 +192,5 @@ lsq_support_info_get_all ( void ) GList * lsq_support_info_get_all_mime_types ( void ) { - return g_hash_table_get_values( lsq_support_info_table ); + return g_hash_table_get_keys( lsq_support_info_table ); } diff --git a/src/archive_store.c b/src/archive_store.c index f38979a..fc8862b 100644 --- a/src/archive_store.c +++ b/src/archive_store.c @@ -43,20 +43,10 @@ sq_archive_store_dispose(GObject *object); /* properties */ enum { - SQ_ARCHIVE_STORE_SHOW_ICONS = 1, - SQ_ARCHIVE_STORE_SORT_FOLDERS_FIRST, + SQ_ARCHIVE_STORE_SORT_FOLDERS_FIRST = 1, SQ_ARCHIVE_STORE_SORT_CASE_SENSITIVE }; -/* signals */ -enum { - SQ_ARCHIVE_STORE_SIGNAL_PWD_CHANGED = 0, - SQ_ARCHIVE_STORE_SIGNAL_NEW_ARCHIVE, - SQ_ARCHIVE_STORE_SIGNAL_FILE_ACTIVATED, - SQ_ARCHIVE_STORE_SIGNAL_COUNT -}; -static gint sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_COUNT]; - static GObjectClass *parent_class; static void @@ -90,12 +80,6 @@ sq_archive_store_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, Gt static gboolean sq_archive_store_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child); -static void -sq_archive_store_file_activated(SQArchiveStore *store, GtkTreePath *path); - -static void -cb_sq_archive_store_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data); - /* tree sortable */ static gboolean sq_archive_store_get_sort_column_id(GtkTreeSortable *sortable, gint *sort_col_id, GtkSortType *order); @@ -118,14 +102,33 @@ static GIcon * sq_archive_store_get_icon_name_for_iter(SQArchiveStore *store, LSQArchiveIter *iter); static void -sq_archive_store_check_trailing(SQArchiveStore *store); - -static void sq_archive_store_refresh(SQArchiveStore *store); static void cb_sq_archive_store_archive_refreshed(LSQArchive *archive, gpointer user_data); +struct _SQArchiveStore +{ + GObject parent; + gint stamp; + LSQArchive *archive; + LSQArchiveIter *entry; + + gint sort_column; + GtkSortType sort_order; + LSQArchiveIter **sort_list; + guint list_size; + struct { + guint _sort_folders_first : 1; + guint _sort_case_sensitive : 1; + } props; +}; + +struct _SQArchiveStoreClass +{ + GObjectClass parent_class; +}; + GType sq_archive_store_get_type(void) { @@ -209,7 +212,6 @@ sq_archive_store_init(SQArchiveStore *as) as->sort_column = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID; as->sort_order = GTK_SORT_ASCENDING; as->sort_list = NULL; - as->props._show_icons = 0; as->props._sort_folders_first = 1; as->props._sort_case_sensitive = 1; } @@ -226,13 +228,6 @@ sq_archive_store_class_init(SQArchiveStoreClass *as_class) parent_class = g_type_class_peek_parent(as_class); - pspec = g_param_spec_boolean("show-icons", - _("Show mime icons"), - _("Show the mime type icons for each entry"), - FALSE, - G_PARAM_READWRITE); - g_object_class_install_property(object_class, SQ_ARCHIVE_STORE_SHOW_ICONS, pspec); - pspec = g_param_spec_boolean("sort-folders-first", _("Sort folders before files"), _("The folders will be put at the top of the list"), @@ -254,9 +249,6 @@ sq_archive_store_set_property(GObject *object, guint prop_id, const GValue *valu SQArchiveStore *store = SQ_ARCHIVE_STORE(object); switch(prop_id) { - case SQ_ARCHIVE_STORE_SHOW_ICONS: - sq_archive_store_set_show_icons(store, g_value_get_boolean(value)); - break; case SQ_ARCHIVE_STORE_SORT_FOLDERS_FIRST: sq_archive_store_set_sort_folders_first(store, g_value_get_boolean(value)); break; @@ -271,9 +263,6 @@ sq_archive_store_get_property(GObject *object, guint prop_id, GValue *value, GPa { switch(prop_id) { - case SQ_ARCHIVE_STORE_SHOW_ICONS: - g_value_set_boolean(value, SQ_ARCHIVE_STORE(object)->props._show_icons?TRUE:FALSE); - break; case SQ_ARCHIVE_STORE_SORT_FOLDERS_FIRST: g_value_set_boolean(value, SQ_ARCHIVE_STORE(object)->props._sort_folders_first?TRUE:FALSE); break; @@ -384,7 +373,6 @@ sq_archive_store_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter) { SQArchiveStore *store; LSQArchive *archive; - LSQArchiveIter *entry; gint pos; GtkTreePath *path; @@ -395,12 +383,8 @@ sq_archive_store_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter) g_return_val_if_fail(archive, NULL); - entry = (LSQArchiveIter *)iter->user_data; pos = GPOINTER_TO_INT(iter->user_data3); - if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry)) - pos++; - path = gtk_tree_path_new(); gtk_tree_path_append_index(path, pos); @@ -409,75 +393,58 @@ sq_archive_store_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter) static void -sq_archive_store_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value) +sq_archive_store_get_value ( + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gint column, + GValue *value + ) { - SQArchiveStore *store; - LSQArchive *archive; - LSQArchiveIter *parent, *entry; - g_debug("%s\n", __FUNCTION__); - - g_return_if_fail (SQ_IS_ARCHIVE_STORE (tree_model)); - - store = SQ_ARCHIVE_STORE(tree_model); - archive = store->archive; - entry = iter->user_data; - - g_return_if_fail(archive); - - if(entry) - { - switch(column) - { - case SQ_ARCHIVE_STORE_EXTRA_PROP_PATH: - g_value_init(value, G_TYPE_STRING); - - parent = lsq_archive_iter_get_parent(entry); - g_value_take_string(value, lsq_archive_iter_get_path(parent)); - lsq_archive_iter_unref(parent); - break; - case SQ_ARCHIVE_STORE_EXTRA_PROP_ICON: - g_value_init(value, G_TYPE_ICON); - - if(store->props._show_icons) - g_value_take_object(value, sq_archive_store_get_icon_name_for_iter(store, entry)); - break; - case LSQ_ARCHIVE_PROP_FILENAME + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT: - if(store->props._show_full_path) - { - g_value_init(value, G_TYPE_STRING); - g_value_take_string(value, lsq_archive_iter_get_path(entry)); - if(!g_utf8_validate(g_value_get_string(value), -1, NULL)) - g_value_take_string(value, g_convert(g_value_get_string(value), -1, "UTF-8", "WINDOWS-1252", NULL, NULL, NULL)); - break; - } - default: - column -= SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT; - if(column < (gint)lsq_archive_n_entry_properties(archive)) - lsq_archive_iter_get_prop_value(entry, column, value); - /* what if it isn't utf-8 */ - if(G_VALUE_HOLDS_STRING(value) && g_value_get_string(value) && !g_utf8_validate(g_value_get_string(value), -1, NULL)) - g_value_take_string(value, g_convert(g_value_get_string(value), -1, "UTF-8", "WINDOWS-1252", NULL, NULL, NULL)); - break; - } - } - else - { - switch(column) - { - case SQ_ARCHIVE_STORE_EXTRA_PROP_ICON: - g_value_init(value, G_TYPE_ICON); - if(store->props._show_icons) - g_value_take_object(value, g_themed_icon_new(GTK_STOCK_GO_UP)); - break; - case LSQ_ARCHIVE_PROP_FILENAME + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT: - g_value_init(value, G_TYPE_STRING); - g_value_set_string(value, ".."); - break; - default: - g_value_init(value, lsq_archive_get_entry_property_type(archive, column - SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT)); - break; - } - } + SQArchiveStore *store; + LSQArchive *archive; + LSQArchiveIter *parent, *entry; + g_debug( "%s\n", __FUNCTION__ ); + + g_return_if_fail( SQ_IS_ARCHIVE_STORE( tree_model ) ); + + store = SQ_ARCHIVE_STORE( tree_model ); + archive = store->archive; + entry = iter->user_data; + + g_return_if_fail( entry ); + + g_return_if_fail( archive ); + + switch ( column ) + { + case SQ_ARCHIVE_STORE_EXTRA_PROP_PATH: + g_value_init( value, G_TYPE_STRING ); + + parent = lsq_archive_iter_get_parent( entry ); + g_value_take_string( value, lsq_archive_iter_get_path( parent ) ); + lsq_archive_iter_unref( parent ); + break; + + case SQ_ARCHIVE_STORE_EXTRA_PROP_FULL_PATH: + g_value_init( value, G_TYPE_STRING ); + g_value_take_string( value, lsq_archive_iter_get_path( entry ) ); + break; + + case SQ_ARCHIVE_STORE_EXTRA_PROP_ICON: + g_value_init( value, G_TYPE_ICON ); + + g_value_take_object( value, sq_archive_store_get_icon_name_for_iter( store, entry ) ); + break; + + default: + column -= SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT; + if ( column < (gint)lsq_archive_n_entry_properties( archive ) ) + lsq_archive_iter_get_prop_value( entry, column, value ); + break; + } + /* what if it isn't utf-8 */ + if ( G_VALUE_HOLDS_STRING( value ) && g_value_get_string( value ) && ! g_utf8_validate( g_value_get_string( value ), -1, NULL ) ) + g_value_take_string( value, g_convert( g_value_get_string( value ), -1, "UTF-8", "WINDOWS-1252", NULL, NULL, NULL ) ); } static gboolean @@ -530,19 +497,11 @@ sq_archive_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, Gtk #ifdef DEBUG g_return_val_if_fail(archive, FALSE); - g_return_val_if_fail(entry, FALSE); #endif /* only support lists: parent is always NULL */ g_return_val_if_fail(parent == NULL, FALSE); - if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry)) - { - entry = NULL; - iter->user_data3 = GINT_TO_POINTER(-1); - } - else - { if(store->sort_list) entry = store->sort_list[0]; else @@ -551,7 +510,6 @@ sq_archive_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, Gtk g_return_val_if_fail(entry, FALSE); iter->user_data3 = GINT_TO_POINTER(0); - } iter->stamp = store->stamp; iter->user_data = entry; @@ -571,7 +529,6 @@ sq_archive_store_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter) { SQArchiveStore *store; LSQArchive *archive; - LSQArchiveIter *entry; g_debug("%s\n", __FUNCTION__); @@ -584,7 +541,6 @@ sq_archive_store_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter) #ifdef DEBUG g_return_val_if_fail(archive, 0); - g_return_val_if_fail(entry, 0); #endif /* only support lists: iter is always NULL */ @@ -610,22 +566,12 @@ sq_archive_store_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, Gt #ifdef DEBUG g_return_val_if_fail(archive, FALSE); - g_return_val_if_fail(entry, FALSE); g_return_val_if_fail(iter, FALSE); #endif /* only support lists: parent is always NULL */ g_return_val_if_fail(parent == NULL, FALSE); - if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry)) - n--; - - if(n == -1) - { - entry = NULL; - } - else - { if(store->sort_list) entry = store->sort_list[n]; else @@ -633,7 +579,6 @@ sq_archive_store_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, Gt if(!entry) return FALSE; - } iter->stamp = store->stamp; iter->user_data = entry; @@ -796,8 +741,8 @@ sq_archive_entry_compare(SQArchiveStore *store, LSQArchiveIter *a, LSQArchiveIte static void sq_archive_store_sort(SQArchiveStore *store) { - LSQArchiveIter *pentry; - guint psize; + LSQArchiveIter *entry; + guint size; guint i = 0; if(store->sort_list) @@ -811,18 +756,25 @@ sq_archive_store_sort(SQArchiveStore *store) store->sort_list = NULL; } - store->sort_list = g_new(LSQArchiveIter *, psize+1); +#ifdef DEBUG + g_return_if_fail(store->entry); +#endif + + entry = store->entry; + size = lsq_archive_iter_n_children(entry); - for(i = 0; i < psize; ++i) + store->sort_list = g_new(LSQArchiveIter *, size+1); + + for(i = 0; i < size; ++i) { - store->sort_list[i] = lsq_archive_iter_nth_child(pentry, i); + store->sort_list[i] = lsq_archive_iter_nth_child(entry, i); } - if(psize && store->sort_column >= SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT) + if(size && store->sort_column >= SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT) { - sq_archive_quicksort(store, 0, psize-1); - sq_archive_insertionsort(store, 0, psize-1); + sq_archive_quicksort(store, 0, size-1); + sq_archive_insertionsort(store, 0, size-1); } - store->sort_list[psize] = NULL; + store->sort_list[size] = NULL; } static inline void @@ -898,27 +850,17 @@ sq_archive_store_get_icon_name_for_iter(SQArchiveStore *store, LSQArchiveIter *i return g_content_type_get_icon( lsq_archive_iter_get_content_type( iter ) ); } -GtkTreeModel * -sq_archive_store_new(gboolean show_icons, gboolean show_up_dir) +SQArchiveStore * +sq_archive_store_new (void) { - SQArchiveStore *tree_model; - - tree_model = g_object_new(SQ_TYPE_ARCHIVE_STORE, NULL); + SQArchiveStore *store; - tree_model->props._show_icons = show_icons?1:0; - tree_model->props._show_up_dir = show_up_dir?1:0; + store = g_object_new( SQ_TYPE_ARCHIVE_STORE, NULL ); - if(tree_model->props._sort_folders_first) - tree_model->sort_column = SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT + LSQ_ARCHIVE_PROP_FILENAME; + if ( store->props._sort_folders_first ) + store->sort_column = SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT + LSQ_ARCHIVE_PROP_FILENAME; - return GTK_TREE_MODEL(tree_model); -} - -void -sq_archive_store_connect_treeview(SQArchiveStore *store, GtkTreeView *treeview) -{ - store->treeview = treeview; - g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_sq_archive_store_row_activated), store); + return store; } static void @@ -981,84 +923,6 @@ sq_archive_store_refresh(SQArchiveStore *store) store->list_size = new_size; - printf("> %d\n", new_size); - -} - -static void -cb_sq_archive_store_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) -{ - sq_archive_store_file_activated(SQ_ARCHIVE_STORE(user_data), path); -} - -static void -sq_archive_store_file_activated(SQArchiveStore *store, GtkTreePath *path) -{ - LSQArchive *archive; - LSQArchiveIter *entry; - gint *indices; - gint depth; - gint index_; - - archive = store->archive; - - g_return_if_fail(archive); - g_return_if_fail(entry); - - indices = gtk_tree_path_get_indices(path); - depth = gtk_tree_path_get_depth(path) - 1; - - /* only support list: depth is always 0 */ - g_return_if_fail(depth == 0); - - index_ = indices[depth]; - - if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry)) - index_--; - - if(index_ == -1) - { - entry = lsq_archive_iter_get_parent(entry); - } - else - { - if(store->sort_list) - entry = store->sort_list[index_]; - else - entry = NULL; - - g_return_if_fail(entry); - - /* Signal file-activated */ - if(!lsq_archive_iter_is_directory(entry)) - { -#ifdef DEBUG - g_debug("file clicked"); -#endif - g_signal_emit(store, sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_FILE_ACTIVATED], 0, entry, NULL); - return; - } - } - - sq_archive_store_sort(store); - sq_archive_store_refresh(store); - //g_signal_emit(store, sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_PWD_CHANGED], 0, entry, NULL); -} - -void -sq_archive_store_go_up(SQArchiveStore *store) -{ - LSQArchive *archive = store->archive; - LSQArchiveIter *entry; - - g_return_if_fail(archive); - g_return_if_fail(entry); - - g_return_if_fail((entry = lsq_archive_iter_get_parent(entry))); - - sq_archive_store_sort(store); - sq_archive_store_refresh(store); - //g_signal_emit(store, sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_PWD_CHANGED], 0, entry, NULL); } void @@ -1066,9 +930,6 @@ sq_archive_store_set_archive(SQArchiveStore *store, LSQArchive *archive) { guint i = 0; GtkTreePath *path_ = NULL; - GtkTreeIter iter; - GList *list_iter; - LSQArchiveIter *root_entry; g_return_if_fail(store); @@ -1108,6 +969,8 @@ sq_archive_store_set_archive(SQArchiveStore *store, LSQArchive *archive) { g_signal_handlers_disconnect_by_func(store->archive, cb_sq_archive_store_archive_refreshed, store); /* g_signal_handlers_disconnect_by_func(store->archive, cb_sq_archive_store_archive_path_changed, store); */ + lsq_archive_iter_unref( store->entry ); + store->entry = NULL; g_object_unref(store->archive); store->archive = NULL; } @@ -1124,57 +987,55 @@ sq_archive_store_set_archive(SQArchiveStore *store, LSQArchive *archive) store->archive = archive; store->entry = lsq_archive_get_iter(archive, NULL); + ++store->stamp; + g_signal_connect(store->archive, "refreshed", G_CALLBACK(cb_sq_archive_store_archive_refreshed), store); - lsq_archive_operate( store->archive, LSQ_COMMAND_TYPE_REFRESH, NULL, NULL, NULL, NULL ); + g_object_unref(lsq_archive_operate( store->archive, LSQ_COMMAND_TYPE_REFRESH, NULL, NULL, NULL, NULL )); } LSQArchiveIter * -sq_archive_store_get_pwd(SQArchiveStore *store) +sq_archive_store_get_root ( SQArchiveStore *store ) { - LSQArchiveIter *iter; #ifdef DEBUG - g_return_val_if_fail(store, NULL); - g_return_val_if_fail(SQ_IS_ARCHIVE_STORE(store), NULL); + g_return_val_if_fail( SQ_IS_ARCHIVE_STORE( store ), NULL ); #endif - return NULL; + return store->entry; } gboolean -sq_archive_store_set_pwd(SQArchiveStore *store, LSQArchiveIter *path) +sq_archive_store_set_root ( + SQArchiveStore *store, + LSQArchiveIter *path + ) { - /* should check if the iter is of the current archive */ + /* should check if the iter is of the current archive */ - g_return_val_if_fail(store, FALSE); + g_return_val_if_fail( SQ_IS_ARCHIVE_STORE( store ), FALSE ); - if(!store->archive) - return FALSE; + if ( NULL == store->archive ) + return FALSE; - if(lsq_archive_iter_is_directory(path)) - { - sq_archive_store_sort(store); - sq_archive_store_refresh(store); + if ( NULL == path ) + path = lsq_archive_get_iter( store->archive, NULL ); - g_signal_emit(store, sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_PWD_CHANGED], 0, path, NULL); - return TRUE; - } - else - { -#ifdef DEBUG - g_debug("file activated"); -#endif - g_signal_emit(store, sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_FILE_ACTIVATED], 0, lsq_archive_iter_get_filename(path), NULL); - } + if ( ! lsq_archive_iter_is_directory( path ) ) + return FALSE; - return FALSE; -} + if ( path == store->entry ) + return TRUE; -gboolean -sq_archive_store_get_show_icons(SQArchiveStore *store) -{ - return store->props._show_icons; + lsq_archive_iter_unref( store->entry ); + store->entry = lsq_archive_iter_ref( path ); + + ++store->stamp; + + sq_archive_store_sort(store); + sq_archive_store_refresh(store); + + return TRUE; } gboolean @@ -1190,20 +1051,6 @@ sq_archive_store_get_sort_folders_first(SQArchiveStore *store) } void -sq_archive_store_set_show_icons(SQArchiveStore *store, gboolean show) -{ - show = show?1:0; - - if(store->props._show_icons != show) - { - store->props._show_icons = show; - if(store->archive) - sq_archive_store_refresh(store); - g_object_notify(G_OBJECT(store), "show-icons"); - } -} - -void sq_archive_store_set_sort_case_sensitive(SQArchiveStore *store, gboolean sort) { sort = sort?1:0; @@ -1267,8 +1114,6 @@ static void cb_sq_archive_store_archive_refreshed(LSQArchive *archive, gpointer user_data) { SQArchiveStore *store = SQ_ARCHIVE_STORE(user_data); - GList *iter; - LSQArchiveIter *aIter; sq_archive_store_sort(store); diff --git a/src/archive_store.h b/src/archive_store.h index 191e626..49c3fa5 100644 --- a/src/archive_store.h +++ b/src/archive_store.h @@ -38,77 +38,56 @@ typedef struct _SQArchiveStore SQArchiveStore; -struct _SQArchiveStore -{ - GObject parent; - gint stamp; - LSQArchive *archive; - LSQArchiveIter *entry; - - gint sort_column; - GtkSortType sort_order; - LSQArchiveIter **sort_list; - guint list_size; - GtkTreeView *treeview; - struct { - guint _show_full_path :1; - guint _show_icons : 1; - guint _show_up_dir : 1; - guint _sort_folders_first : 1; - guint _sort_case_sensitive : 1; - } props; -}; - typedef struct _SQArchiveStoreClass SQArchiveStoreClass; -struct _SQArchiveStoreClass -{ - GObjectClass parent_class; -}; - /* archive iter extra props columns */ enum { SQ_ARCHIVE_STORE_EXTRA_PROP_PATH = 0, + SQ_ARCHIVE_STORE_EXTRA_PROP_FULL_PATH, SQ_ARCHIVE_STORE_EXTRA_PROP_ICON, SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT }; GType sq_archive_store_get_type(); -GtkTreeModel * -sq_archive_store_new (gboolean show_icons, gboolean show_up_dir); -void sq_archive_store_connect_treeview(SQArchiveStore *store, GtkTreeView *treeview); -void sq_archive_store_connect_iconview(SQArchiveStore *store, GtkIconView *iconview); -void sq_archive_store_go_up(SQArchiveStore *store); -LSQArchiveIter * sq_archive_store_get_pwd(SQArchiveStore *store); -gboolean sq_archive_store_set_pwd(SQArchiveStore *store, LSQArchiveIter *path); -void sq_archive_store_set_icon_theme(SQArchiveStore *store, GtkIconTheme *icon_theme); - -gboolean sq_archive_store_get_show_full_path(SQArchiveStore *); -gboolean sq_archive_store_get_show_icons(SQArchiveStore *store); -gboolean sq_archive_store_get_sort_case_sensitive(SQArchiveStore *store); -gboolean sq_archive_store_get_sort_folders_first(SQArchiveStore *store); - -void sq_archive_store_set_show_full_path(SQArchiveStore *, gboolean); -void sq_archive_store_set_show_icons(SQArchiveStore *, gboolean); -void sq_archive_store_set_sort_case_sensitive(SQArchiveStore *, gboolean); -void sq_archive_store_set_sort_folders_first(SQArchiveStore *, gboolean); - -LSQArchiveIter *sq_archive_store_get_archive_iter(SQArchiveStore *, GtkTreeIter *); +SQArchiveStore * +sq_archive_store_new (void); +LSQArchiveIter * +sq_archive_store_get_root ( SQArchiveStore * ); gboolean -sq_archive_store_has_history(SQArchiveStore *store); +sq_archive_store_set_root ( + SQArchiveStore *store, + LSQArchiveIter *path + ); + +gboolean +sq_archive_store_get_sort_case_sensitive ( SQArchiveStore * ); gboolean -sq_archive_store_has_future(SQArchiveStore *store); +sq_archive_store_get_sort_folders_first ( SQArchiveStore * ); + void -sq_archive_store_go_back(SQArchiveStore *store); +sq_archive_store_set_sort_case_sensitive ( + SQArchiveStore *, + gboolean + ); void -sq_archive_store_go_forward(SQArchiveStore *store); +sq_archive_store_set_sort_folders_first ( + SQArchiveStore *, + gboolean + ); + LSQArchiveIter * -sq_archive_store_get_trailing(SQArchiveStore *store); +sq_archive_store_get_archive_iter ( + SQArchiveStore *, + GtkTreeIter * + ); LSQArchive * -sq_archive_store_get_archive(SQArchiveStore *archive_store); +sq_archive_store_get_archive ( SQArchiveStore * ); -void sq_archive_store_set_archive(SQArchiveStore *archive_store, LSQArchive *archive); +void sq_archive_store_set_archive ( + SQArchiveStore *, + LSQArchive * + ); #endif /* __SQRCHIVER_ARCHIVE_STORE_H__ */ diff --git a/src/main.c b/src/main.c index 35b60de..c504636 100644 --- a/src/main.c +++ b/src/main.c @@ -89,10 +89,7 @@ main(int argc, char **argv) g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_widget_show_all (window); - GDK_THREADS_ENTER(); gtk_main(); - GDK_THREADS_LEAVE(); - lsq_shutdown(); xfconf_shutdown(); diff --git a/src/main_window.c b/src/main_window.c index 52ca797..7f01ea5 100644 --- a/src/main_window.c +++ b/src/main_window.c @@ -37,274 +37,449 @@ #define SQ_RECENT_FILES_GROUP "Accessories" static void -sq_main_window_init(SQMainWindow *); -static void -sq_main_window_class_init(SQMainWindowClass *); -static void -sq_main_window_dispose(GObject *object); - -static GObjectClass *parent_class; +sq_main_window_finalize ( GObject *object ); static void -cb_sq_main_window_open_archive ( - GtkWidget *, - gpointer - ); +reset_columns ( GtkTreeView *treeview ); static void -cb_sq_main_window_save_copy ( - GtkWidget *, +cb_sq_main_window_open_archive ( + GtkAction *, gpointer ); static void cb_sq_main_window_properties ( - GtkWidget *, + GtkAction *, gpointer ); static void cb_sq_main_window_close ( - GtkWidget *, + GtkAction *, gpointer ); static void cb_sq_main_window_quit ( - GtkWidget *, + GtkAction *, gpointer ); static void cb_sq_main_window_preferences ( - GtkWidget *, + GtkAction *, + gpointer + ); + +static void +cb_sq_main_window_reload ( + GtkAction *, gpointer ); static void cb_sq_main_window_contents ( - GtkWidget *, + GtkAction *, gpointer ); static void cb_sq_main_window_about ( - GtkWidget *, + GtkAction *, + gpointer + ); + +static void +cb_sq_main_window_pathbar ( + GtkToggleAction *, + gpointer + ); + +static void +cb_sq_main_window_toolbar ( + GtkToggleAction *, + gpointer + ); + +static void +cb_sq_main_window_menubar ( + GtkToggleAction *, + gpointer + ); + +static void +cb_sq_main_window_row_activated ( + GtkTreeView *, + GtkTreePath *, + GtkTreeViewColumn *, gpointer ); static GtkActionEntry action_entries[] = { -/* File Menu */ - { "file-menu", - NULL, - N_ ("_File"), - NULL, }, - { "open", - "document-open", /* Icon-name */ - N_ ("_Open..."), /* Label-text */ - "<control>O", /* Keyboard shortcut */ - N_ ("Open an archive"), /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_open_archive), }, - { "save-copy", - GTK_STOCK_SAVE_AS, /* Icon-name */ - N_ ("_Save copy..."), /* Label-text */ - "<control>s", /* Keyboard shortcut */ - N_ ("Save a copy of the image"), /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_save_copy), }, - { "properties", - GTK_STOCK_PROPERTIES, /* Icon-name */ - N_ ("_Properties..."), /* Label-text */ - NULL, /* Keyboard shortcut */ - N_ ("Show file properties"), /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_properties), }, - { "close", - GTK_STOCK_CLOSE, /* Icon-name */ - N_ ("_Close"), /* Label-text */ - "<control>W", /* Keyboard shortcut */ - N_ ("Close this archive"), /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_close), }, - { "quit", - GTK_STOCK_QUIT, /* Icon-name */ - N_ ("_Quit"), /* Label-text */ - "<control>Q", /* Keyboard shortcut */ - N_ ("Quit Squeeze"), /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_quit), }, -/* Edit Menu */ - { "edit-menu", - NULL, - N_ ("_Edit"), - NULL, }, - { "preferences", - GTK_STOCK_PREFERENCES, /* Icon-name */ - N_ ("_Preferences..."), /* Label-text */ - NULL, /* Keyboard shortcut */ - NULL, /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_preferences), }, -/* Help Menu */ - { "help-menu", - NULL, - N_ ("_Help"), - NULL, }, - { "contents", - GTK_STOCK_HELP, /* Icon-name */ - N_ ("_Contents"), /* Label-text */ - "F1", /* Keyboard shortcut */ - N_ ("Display squeeze user manual"), /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_contents), }, - { "about", - GTK_STOCK_ABOUT, /* Icon-name */ - N_ ("_About"), /* Label-text */ - NULL, /* Keyboard shortcut */ - N_ ("Display information about squeeze"), /* Tooltip text */ - G_CALLBACK (cb_sq_main_window_about), }, - { "tb-menu", - NULL, - NULL, - NULL, } + /* File Menu */ + { "file-menu", + NULL, + N_("_File"), + NULL }, + { "open", + "document-open", /* Icon-name */ + N_("_Open..."), /* Label-text */ + "<control>O", /* Keyboard shortcut */ + N_("Open an archive"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_open_archive ) }, + { "properties", + GTK_STOCK_PROPERTIES, /* Icon-name */ + N_("_Properties..."), /* Label-text */ + NULL, /* Keyboard shortcut */ + N_("Show file properties"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_properties ) }, + { "close", + GTK_STOCK_CLOSE, /* Icon-name */ + N_("_Close"), /* Label-text */ + "<control>W", /* Keyboard shortcut */ + N_("Close this archive"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_close ) }, + { "quit", + GTK_STOCK_QUIT, /* Icon-name */ + N_("_Quit"), /* Label-text */ + "<control>Q", /* Keyboard shortcut */ + N_("Quit Squeeze"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_quit ) }, + /* Edit Menu */ + { "edit-menu", + NULL, + N_("_Edit"), + NULL }, + { "preferences", + GTK_STOCK_PREFERENCES, /* Icon-name */ + N_("_Preferences..."), /* Label-text */ + NULL, /* Keyboard shortcut */ + N_("Edit Squeeze preferences"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_preferences ) }, + /* View Menu */ + { "view-menu", + NULL, + N_("_View"), + NULL }, + { "reload", + GTK_STOCK_REFRESH, /* Icon-name */ + N_("_Reload"), /* Label-text */ + "<control>R", /* Keyboard shortcut */ + N_("Reload the archive"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_reload ) }, + { "view-location-selector-menu", + NULL, + N_("_Location Selector"), + NULL }, + /* Help Menu */ + { "help-menu", + NULL, + N_("_Help"), + NULL }, + { "contents", + GTK_STOCK_HELP, /* Icon-name */ + N_ ("_Contents"), /* Label-text */ + "F1", /* Keyboard shortcut */ + N_ ("Display Squeeze user manual"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_contents ) }, + { "about", + GTK_STOCK_ABOUT, /* Icon-name */ + N_ ("_About"), /* Label-text */ + NULL, /* Keyboard shortcut */ + N_ ("Display information about Squeeze"), /* Tooltip text */ + G_CALLBACK( cb_sq_main_window_about ) }, + { "tb-menu", + NULL, + NULL, + NULL } +}; + +static const GtkToggleActionEntry toggle_action_entries[] = +{ + { "view-location-selector-pathbar", + NULL, + N_("_Pathbar Style"), + NULL, + N_("Modern approach with buttons that correspond to folders"), + G_CALLBACK (cb_sq_main_window_pathbar), + FALSE }, + { "view-location-selector-toolbar", + NULL, + N_ ("_Toolbar Style"), + NULL, + N_ ("Traditional approach with location bar and navigation buttons"), + G_CALLBACK (cb_sq_main_window_toolbar), + FALSE }, + { "view-menubar", + NULL, + N_("_Menubar"), + "<control>M", + N_("Change the visibility of this window's menubar"), + G_CALLBACK( cb_sq_main_window_menubar ), + TRUE } }; -struct _SQMainWindowPriv + +struct _SQMainWindow { - GtkWidget *menubar; + GtkWindow parent; - GtkActionGroup *action_group; - GtkUIManager *ui_manager; - GtkRecentManager *recent_manager; + GtkWidget *menubar; - GtkTreeModel *archive_store; + GtkActionGroup *action_group; + GtkUIManager *ui_manager; + GtkRecentManager *recent_manager; + + GtkWidget *tree_view; + SQArchiveStore *archive_store; }; -GType -sq_main_window_get_type (void) +struct _SQMainWindowClass { - static GType sq_main_window_type = 0; - - if (!sq_main_window_type) - { - static const GTypeInfo sq_main_window_info = - { - sizeof (SQMainWindowClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) sq_main_window_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (SQMainWindow), - 0, - (GInstanceInitFunc) sq_main_window_init, - NULL - }; - - sq_main_window_type = g_type_register_static (GTK_TYPE_WINDOW, "SQMainWindow", &sq_main_window_info, 0); - } - return sq_main_window_type; -} + GtkWindowClass parent; +}; + +G_DEFINE_TYPE( SQMainWindow, sq_main_window, GTK_TYPE_WINDOW ) static void -sq_main_window_class_init(SQMainWindowClass *window_class) +sq_main_window_class_init ( SQMainWindowClass *window_class ) { - GObjectClass *object_class = G_OBJECT_CLASS (window_class); - - parent_class = g_type_class_peek_parent(window_class); + GObjectClass *object_class = G_OBJECT_CLASS (window_class); - object_class->dispose = sq_main_window_dispose; + object_class->finalize = sq_main_window_finalize; } static void -sq_main_window_dispose(GObject *object) +sq_main_window_finalize ( GObject *object ) { - SQMainWindow *window = SQ_MAIN_WINDOW (object); + SQMainWindow *window = SQ_MAIN_WINDOW( object ); - if (window->priv) - { - if (window->priv->ui_manager) - { - g_object_unref (window->priv->ui_manager); - window->priv->ui_manager = NULL; - } + g_object_unref( window->ui_manager ); + g_object_unref( window->action_group ); - g_free (window->priv); - window->priv = NULL; - } - parent_class->dispose(object); + g_object_unref( window->archive_store ); + + G_OBJECT_CLASS( sq_main_window_parent_class )->finalize( object ); } static void -sq_main_window_init(SQMainWindow *window) +sq_main_window_init ( SQMainWindow *window ) { GtkAccelGroup *accel_group; GtkWidget *main_vbox; GtkWidget *scrolled_window; - GtkWidget *tree_view; - main_vbox = gtk_vbox_new (FALSE, 0); + main_vbox = gtk_vbox_new( FALSE, 0 ); - gtk_window_set_title (GTK_WINDOW (window), SQUEEZE_APP_TITLE); + gtk_window_set_title( GTK_WINDOW (window), SQUEEZE_APP_TITLE ); - window->priv = g_new0(SQMainWindowPriv, 1); - window->priv->ui_manager = gtk_ui_manager_new (); - window->priv->recent_manager = gtk_recent_manager_get_default(); - window->priv->action_group = gtk_action_group_new ("RsttoWindow"); + /* Menu and toolbars */ + window->ui_manager = gtk_ui_manager_new(); + window->recent_manager = gtk_recent_manager_get_default(); + window->action_group = gtk_action_group_new( "SqueezeWindow" ); - gtk_action_group_set_translation_domain ( - window->priv->action_group, - GETTEXT_PACKAGE ); - gtk_action_group_add_actions ( - window->priv->action_group, + gtk_action_group_set_translation_domain( window->action_group, GETTEXT_PACKAGE ); + gtk_action_group_add_actions( + window->action_group, action_entries, - G_N_ELEMENTS (action_entries), - GTK_WIDGET (window) ); - - - accel_group = gtk_ui_manager_get_accel_group (window->priv->ui_manager); - gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); - - gtk_ui_manager_insert_action_group ( - window->priv->ui_manager, - window->priv->action_group, - 0); - gtk_ui_manager_add_ui_from_string ( - window->priv->ui_manager, + G_N_ELEMENTS( action_entries ), + window + ); + gtk_action_group_add_toggle_actions( + window->action_group, + toggle_action_entries, + G_N_ELEMENTS( toggle_action_entries ), + window + ); + + + accel_group = gtk_ui_manager_get_accel_group( window->ui_manager ); + gtk_window_add_accel_group( GTK_WINDOW( window ), accel_group ); + + gtk_ui_manager_insert_action_group( window->ui_manager, window->action_group, 0 ); + gtk_ui_manager_add_ui_from_string( + window->ui_manager, main_window_ui, main_window_ui_length, - NULL ); + NULL + ); - window->priv->menubar = gtk_ui_manager_get_widget (window->priv->ui_manager, "/main-menu"); + window->menubar = gtk_ui_manager_get_widget( window->ui_manager, "/main-menu" ); - gtk_container_add (GTK_CONTAINER (window), main_vbox); - gtk_box_pack_start(GTK_BOX(main_vbox), window->priv->menubar, FALSE, FALSE, 0); + gtk_container_add( GTK_CONTAINER( window ), main_vbox ); + gtk_box_pack_start( GTK_BOX( main_vbox ), window->menubar, FALSE, FALSE, 0 ); - scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy ( - GTK_SCROLLED_WINDOW (scrolled_window), + /* Main part of the window */ + scrolled_window = gtk_scrolled_window_new( NULL, NULL ); + gtk_scrolled_window_set_policy( + GTK_SCROLLED_WINDOW( scrolled_window ), GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type ( - GTK_SCROLLED_WINDOW (scrolled_window), - GTK_SHADOW_IN); + GTK_POLICY_AUTOMATIC + ); + gtk_scrolled_window_set_shadow_type( + GTK_SCROLLED_WINDOW( scrolled_window ), + GTK_SHADOW_IN + ); + + gtk_box_pack_start( GTK_BOX( main_vbox ), scrolled_window, TRUE, TRUE, 0 ); + window->tree_view = gtk_tree_view_new(); - gtk_box_pack_start(GTK_BOX(main_vbox), scrolled_window, FALSE, FALSE, 0); - tree_view = gtk_tree_view_new (); + window->archive_store = sq_archive_store_new(); - window->priv->archive_store = sq_archive_store_new (TRUE, TRUE); + gtk_tree_view_set_model( + GTK_TREE_VIEW( window->tree_view ), + GTK_TREE_MODEL( window->archive_store ) + ); - gtk_tree_view_set_model ( - GTK_TREE_VIEW (tree_view), - GTK_TREE_MODEL (window->priv->archive_store)); + reset_columns( GTK_TREE_VIEW( window->tree_view ) ); - gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view); + g_signal_connect( G_OBJECT( window->tree_view ), "row-activated", G_CALLBACK( cb_sq_main_window_row_activated ), window ); + + gtk_container_add( GTK_CONTAINER( scrolled_window ), window->tree_view ); } GtkWidget * sq_main_window_new (void) { - SQMainWindow *window; + SQMainWindow *window; + + window = g_object_new( SQ_TYPE_MAIN_WINDOW, NULL ); + + return GTK_WIDGET( window ); +} + +static void +reset_columns ( GtkTreeView *treeview ) +{ + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GList *columns, *iter; + + columns = gtk_tree_view_get_columns( treeview ); + + for ( iter = columns; iter; iter = g_list_next( iter ) ) + { + gtk_tree_view_remove_column( treeview, iter->data ); + } + + g_list_free( columns ); + + column = gtk_tree_view_column_new(); + + renderer = gtk_cell_renderer_pixbuf_new(); + g_object_set( + G_OBJECT( renderer ), + "stock-size", GTK_ICON_SIZE_SMALL_TOOLBAR, + NULL + ); + gtk_tree_view_column_pack_start( column, renderer, FALSE ); + gtk_tree_view_column_set_attributes( + column, renderer, + "gicon", SQ_ARCHIVE_STORE_EXTRA_PROP_ICON, + NULL + ); + + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start( column, renderer, TRUE ); + gtk_tree_view_column_set_attributes( + column, renderer, + "text", LSQ_ARCHIVE_PROP_FILENAME + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT, + NULL + ); + + gtk_tree_view_column_set_resizable( column, TRUE ); + gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_AUTOSIZE ); + gtk_tree_view_column_set_sort_column_id( column, LSQ_ARCHIVE_PROP_FILENAME + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT ); + gtk_tree_view_column_set_title( + column, + _("Name") + ); + gtk_tree_view_append_column( treeview, column ); +} + +static void +set_columns ( GtkTreeView *treeview, LSQArchive *archive ) +{ + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + guint x = 0; + + for ( x = LSQ_ARCHIVE_PROP_USER; x < lsq_archive_n_entry_properties( archive ); ++x ) + { + switch ( lsq_archive_get_entry_property_type( archive, x ) ) + { + default: + if ( LSQ_TYPE_DATETIME != lsq_archive_get_entry_property_type( archive, x ) ) + { + g_warn_if_reached(); + continue; + } + case G_TYPE_CHAR: + case G_TYPE_DOUBLE: + case G_TYPE_FLOAT: + case G_TYPE_INT: + case G_TYPE_INT64: + case G_TYPE_LONG: + case G_TYPE_STRING: + case G_TYPE_UINT: + case G_TYPE_UINT64: + case G_TYPE_ULONG: + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes( + lsq_archive_get_entry_property_name( archive, x ), + renderer, + "text", x + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT, + NULL + ); + break; + } + gtk_tree_view_column_set_resizable( column, TRUE ); + gtk_tree_view_column_set_sort_column_id( column, x + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT ); + gtk_tree_view_append_column( treeview, column ); + } + gtk_tree_view_set_search_column( treeview, LSQ_ARCHIVE_PROP_FILENAME + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT ); +} + + +static void +sq_main_window_open_archive ( + SQMainWindow *window, + GFile *file + ) +{ + LSQArchive *archive; + GError *error = NULL; + GtkWidget *err_dialog; - window = g_object_new(SQ_TYPE_MAIN_WINDOW, NULL); + g_return_if_fail( file ); - return GTK_WIDGET(window); + archive = lsq_open_archive( file, &error ); + if ( NULL == archive ) + { + err_dialog = gtk_message_dialog_new( + GTK_WINDOW( window ), + GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s", _("Could not open file") + ); + gtk_message_dialog_format_secondary_text( + GTK_MESSAGE_DIALOG( err_dialog ), + "%s", error->message + ); + gtk_dialog_run( GTK_DIALOG( err_dialog ) ); + gtk_widget_destroy( err_dialog ); + g_clear_error( &error ); + return; + } + + reset_columns( GTK_TREE_VIEW( window->tree_view ) ); + /** Set tree-store with archive */ + sq_archive_store_set_archive( window->archive_store, archive ); + set_columns( GTK_TREE_VIEW( window->tree_view ), archive ); } /** STATIC CALLBACKS **/ @@ -318,79 +493,74 @@ sq_main_window_new (void) */ static void cb_sq_main_window_open_archive ( - GtkWidget *widget, + GtkAction *action, gpointer user_data ) { - SQMainWindow *window = SQ_MAIN_WINDOW (user_data); + SQMainWindow *window = SQ_MAIN_WINDOW( user_data ); - GtkWidget *dialog, *err_dialog; + GtkWidget *dialog; + GList *mime, *iter; GtkFileFilter *filter; GFile *file; - LSQArchive *archive; gint response; filter = gtk_file_filter_new(); - - dialog = gtk_file_chooser_dialog_new(_("Open archive"), - GTK_WINDOW(window), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); - - gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE); - - response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_hide (dialog); - if(response == GTK_RESPONSE_OK) + mime = lsq_support_info_get_all_mime_types(); + for ( iter = mime; NULL != iter; iter = g_list_next( iter ) ) + { + gtk_file_filter_add_mime_type( filter, iter->data ); + } + g_list_free( mime ); + + dialog = gtk_file_chooser_dialog_new( + _("Open archive"), + GTK_WINDOW( window ), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL + ); + + gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( dialog ), FALSE); + gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( dialog ), filter ); + + response = gtk_dialog_run( GTK_DIALOG( dialog ) ); + gtk_widget_hide( dialog ); + if ( GTK_RESPONSE_OK == response ) { - file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); - if ( file != NULL ) + file = gtk_file_chooser_get_file( GTK_FILE_CHOOSER( dialog ) ); + if ( NULL != file ) { - archive = lsq_open_archive (file, NULL); - if (archive == NULL) - { - err_dialog = gtk_message_dialog_new(GTK_WINDOW(window), - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("Could not open file")); - gtk_dialog_run(GTK_DIALOG(err_dialog)); - gtk_widget_destroy(err_dialog); - return; - } - - /** Set tree-store with archive */ - sq_archive_store_set_archive (window->priv->archive_store, archive); + sq_main_window_open_archive( window, file ); } } - return; + gtk_widget_destroy( dialog ); } static void -cb_sq_main_window_save_copy ( - GtkWidget *widget, +cb_sq_main_window_properties ( + GtkAction *action, gpointer user_data ) { return; } + static void -cb_sq_main_window_properties ( - GtkWidget *widget, +cb_sq_main_window_close ( + GtkAction *action, gpointer user_data ) { return; } - static void -cb_sq_main_window_close ( - GtkWidget *widget, +cb_sq_main_window_quit ( + GtkAction *action, gpointer user_data ) { @@ -398,8 +568,8 @@ cb_sq_main_window_close ( } static void -cb_sq_main_window_quit ( - GtkWidget *widget, +cb_sq_main_window_preferences ( + GtkAction *action, gpointer user_data ) { @@ -407,17 +577,22 @@ cb_sq_main_window_quit ( } static void -cb_sq_main_window_preferences ( - GtkWidget *widget, +cb_sq_main_window_reload ( + GtkAction *action, gpointer user_data ) { - return; + SQMainWindow *window = SQ_MAIN_WINDOW (user_data); + LSQArchive *archive; + + archive = sq_archive_store_get_archive( window->archive_store ); + if ( NULL != archive ) + g_object_unref( lsq_archive_operate( archive, LSQ_COMMAND_TYPE_REFRESH, NULL, NULL, NULL, NULL ) ); } static void cb_sq_main_window_contents ( - GtkWidget *widget, + GtkAction *action, gpointer user_data ) { @@ -432,7 +607,7 @@ cb_sq_main_window_contents ( static void cb_sq_main_window_about ( - GtkWidget *widget, + GtkAction *action, gpointer user_data ) { @@ -460,11 +635,89 @@ cb_sq_main_window_about ( gtk_about_dialog_set_license((GtkAboutDialog *)about_dialog, xfce_get_license_text(XFCE_LICENSE_TEXT_GPL)); gtk_about_dialog_set_copyright((GtkAboutDialog *)about_dialog, - "Copyright \302\251 2006-2013 Xfce Developers"); + "Copyright \302\251 2006-2014 Xfce Developers"); gtk_dialog_run(GTK_DIALOG(about_dialog)); gtk_widget_destroy(about_dialog); +} + +static void +cb_sq_main_window_pathbar ( + GtkToggleAction *action, + gpointer user_data + ) +{ + SQMainWindow *window = SQ_MAIN_WINDOW (user_data); + gboolean active; + GtkAction *other_action; + + active = gtk_toggle_action_get_active( action ); + if ( active ) + { + other_action = gtk_action_group_get_action( + window->action_group, + "view-location-selector-toolbar" + ); + + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION( other_action ), FALSE ); + } +} + +static void +cb_sq_main_window_toolbar ( + GtkToggleAction *action, + gpointer user_data + ) +{ + SQMainWindow *window = SQ_MAIN_WINDOW (user_data); + gboolean active; + GtkAction *other_action; + + active = gtk_toggle_action_get_active( action ); + + if ( active ) + { + other_action = gtk_action_group_get_action( + window->action_group, + "view-location-selector-pathbar" + ); + + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION( other_action ), FALSE ); + } +} + +static void +cb_sq_main_window_menubar ( + GtkToggleAction *action, + gpointer user_data + ) +{ return; } + +static void +cb_sq_main_window_row_activated ( + GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column, + gpointer user_data + ) +{ + SQMainWindow *window = SQ_MAIN_WINDOW (user_data); + GtkTreeIter iter; + LSQArchiveIter *entry; + + if ( ! gtk_tree_model_get_iter( GTK_TREE_MODEL( window->archive_store ), &iter, path ) ) + g_return_if_reached(); + + entry = sq_archive_store_get_archive_iter( window->archive_store, &iter ); + + if ( lsq_archive_iter_is_directory( entry ) ) + { + sq_archive_store_set_root( window->archive_store, entry ); + } + + lsq_archive_iter_unref( entry ); +} diff --git a/src/main_window.h b/src/main_window.h index 2e7baae..6704eb9 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -21,41 +21,30 @@ G_BEGIN_DECLS #define SQ_TYPE_MAIN_WINDOW sq_main_window_get_type() -#define SQ_MAIN_WINDOW(obj) ( \ - G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - sq_main_window_get_type(), \ - SQMainWindow)) +#define SQ_MAIN_WINDOW(obj) \ + G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + sq_main_window_get_type(), \ + SQMainWindow) -#define SQ_IS_MAIN_WINDOW(obj) ( \ - G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - sq_main_window_get_type())) +#define SQ_IS_MAIN_WINDOW(obj) \ + G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + sq_main_window_get_type()) -#define SQ_MAIN_WINDOW_CLASS(klass) ( \ - G_TYPE_CHECK_CLASS_CAST ((klass), \ - sq_main_window_get_type(), \ - SQMainWindowClass)) +#define SQ_MAIN_WINDOW_CLASS(klass) \ + G_TYPE_CHECK_CLASS_CAST ((klass), \ + sq_main_window_get_type(), \ + SQMainWindowClass) -#define SQ_IS_MAIN_WINDOW_CLASS(klass) ( \ - G_TYPE_CHECK_CLASS_TYPE ((klass), \ - sq_main_window_get_type())) +#define SQ_IS_MAIN_WINDOW_CLASS(klass) \ + G_TYPE_CHECK_CLASS_TYPE ((klass), \ + sq_main_window_get_type()) typedef struct _SQMainWindowPriv SQMainWindowPriv; typedef struct _SQMainWindow SQMainWindow; -struct _SQMainWindow -{ - GtkWindow parent; - SQMainWindowPriv *priv; -}; - typedef struct _SQMainWindowClass SQMainWindowClass; -struct _SQMainWindowClass -{ - GtkWindowClass parent; -}; - GtkWidget * sq_main_window_new (void); diff --git a/src/main_window_ui.xml b/src/main_window_ui.xml index a6cfdc4..85f5444 100644 --- a/src/main_window_ui.xml +++ b/src/main_window_ui.xml @@ -4,8 +4,6 @@ <menuitem action="open"/> <placeholder name="placeholder-open-recent"/> <separator/> - <menuitem action="save-copy"/> - <separator/> <menuitem action="properties"/> <menuitem action="close"/> <menuitem action="quit"/> @@ -13,9 +11,25 @@ <menu action="edit-menu"> <menuitem action="preferences"/> </menu> + <menu action="view-menu"> + <menuitem action="reload" /> + <separator /> + <menu action="view-location-selector-menu"> + <menuitem action="view-location-selector-pathbar" /> + <menuitem action="view-location-selector-toolbar" /> + </menu> + <menuitem action="view-menubar" /> + </menu> <menu action="help-menu"> <menuitem action="contents"/> <menuitem action="about"/> </menu> </menubar> + + <toolbar name="location-toolbar"> + <toolitem action="back" /> + <toolitem action="forward" /> + <toolitem action="parent-node" /> + <toolitem action="root-node" /> + </toolbar> </ui> -- To stop receiving notification emails like this one, please contact the administrator of this repository. _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits