Skip to content
Browse files

library: hook up the open button to the library selection when the li…

…brary tab is active (recent documents)
  • Loading branch information...
1 parent d4eb944 commit 9ac1115ae8c6da50f1eac55d0f37c0e5369a5c13 @rhdunn committed
Showing with 61 additions and 52 deletions.
  1. +27 −47 src/cainteoir.cpp
  2. +2 −1 src/cainteoir.hpp
  3. +29 −3 src/library.cpp
  4. +3 −1 src/library.hpp
View
74 src/cainteoir.cpp
@@ -150,22 +150,13 @@ static void on_button_clicked(GtkWidget *widget, void *data)
((cbd->window)->*(cbd->callback))();
}
-static GtkWidget *create_stock_button(const char *stock, Cainteoir *window, callback_function callback, GtkWidget *menu=nullptr)
+static GtkWidget *create_stock_button(const char *stock, Cainteoir *window, callback_function callback)
{
CallbackData *data = g_slice_new(CallbackData);
data->window = window;
data->callback = callback;
- GtkToolItem *button = nullptr;
- if (menu)
- {
- button = gtk_menu_tool_button_new_from_stock(stock);
- gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(button), menu);
- }
- else
- {
- button = gtk_tool_button_new_from_stock(stock);
- }
+ GtkToolItem *button = gtk_tool_button_new_from_stock(stock);
gtk_container_set_border_width(GTK_CONTAINER(button), 0);
g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), data);
return GTK_WIDGET(button);
@@ -257,7 +248,7 @@ Cainteoir::Cainteoir(const char *filename)
readButton = create_stock_button(GTK_STOCK_MEDIA_PLAY, this, &Cainteoir::read);
stopButton = create_stock_button(GTK_STOCK_MEDIA_STOP, this, &Cainteoir::stop);
recordButton = create_stock_button(GTK_STOCK_MEDIA_RECORD, this, &Cainteoir::record);
- openButton = create_stock_button(GTK_STOCK_OPEN, this, &Cainteoir::on_open_document, create_file_chooser_menu());
+ openButton = create_stock_button(GTK_STOCK_OPEN, this, &Cainteoir::on_open_document);
GtkWidget *topbar = gtk_toolbar_new();
gtk_widget_set_name(topbar, "topbar");
@@ -325,9 +316,10 @@ Cainteoir::Cainteoir(const char *filename)
int voice_page = gtk_notebook_append_page(GTK_NOTEBOOK(view), GTK_WIDGET(voiceSelection->gobj()), nullptr);
int lib_page = gtk_notebook_append_page(GTK_NOTEBOOK(view), *library, nullptr);
- navbar.add_paged_button(i18n("Library"), GTK_NOTEBOOK(view), lib_page);
- navbar.set_active_button(navbar.add_paged_button(i18n("Document"), GTK_NOTEBOOK(view), doc_page));
+ library_button = navbar.add_paged_button(i18n("Library"), GTK_NOTEBOOK(view), lib_page);
+ document_button = navbar.add_paged_button(i18n("Document"), GTK_NOTEBOOK(view), doc_page);
navbar.add_paged_button(i18n("Voice"), GTK_NOTEBOOK(view), voice_page);
+ navbar.set_active_button(document_button);
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(window), box);
@@ -349,17 +341,25 @@ Cainteoir::Cainteoir(const char *filename)
void Cainteoir::on_open_document()
{
- rql::results formats = rql::select(tts_metadata,
- rql::both(rql::matches(rql::predicate, rdf::rdf("type")),
- rql::matches(rql::object, rdf::tts("DocumentFormat"))));
-
- std::string filename = select_file(GTK_WINDOW(window),
- i18n("Open Document"),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_OPEN,
- settings("document.filename").as<std::string>().c_str(),
- settings("document.mimetype", "text/plain").as<std::string>(),
- tts_metadata, formats);
+ std::string filename;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(library_button)))
+ {
+ filename = library->get_filename();
+ }
+ else
+ {
+ rql::results formats = rql::select(tts_metadata,
+ rql::both(rql::matches(rql::predicate, rdf::rdf("type")),
+ rql::matches(rql::object, rdf::tts("DocumentFormat"))));
+
+ filename = select_file(GTK_WINDOW(window),
+ i18n("Open Document"),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_OPEN,
+ settings("document.filename").as<std::string>().c_str(),
+ settings("document.mimetype", "text/plain").as<std::string>(),
+ tts_metadata, formats);
+ }
if (!filename.empty())
load_document(filename);
@@ -558,6 +558,8 @@ bool Cainteoir::load_document(std::string filename, bool from_constructor)
if (lang.empty())
lang = "en";
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(document_button), TRUE);
+
voiceSelection->set_language(lang);
switch_voice_by_language(lang);
}
@@ -581,28 +583,6 @@ bool Cainteoir::load_document(std::string filename, bool from_constructor)
return ret;
}
-GtkWidget *Cainteoir::create_file_chooser_menu()
-{
- GtkWidget *recent = gtk_recent_chooser_menu_new_for_manager(recentManager);
- gtk_recent_chooser_menu_set_show_numbers(GTK_RECENT_CHOOSER_MENU(recent), TRUE);
- gtk_recent_chooser_set_sort_type(GTK_RECENT_CHOOSER(recent), GTK_RECENT_SORT_MRU);
- gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recent), recentFilter);
- gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER(recent), 10);
-
- GtkWidget *separator = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(recent), separator);
- gtk_widget_show(separator);
-
- GtkWidget *more = gtk_menu_item_new_with_mnemonic(i18n("_More Documents..."));
- gtk_menu_shell_append(GTK_MENU_SHELL(recent), more);
- gtk_widget_show(more);
-
- g_signal_connect(recent, "item-activated", G_CALLBACK(on_recent_item_activated), this);
- g_signal_connect(more, "activate", G_CALLBACK(on_recent_files_dialog), this);
-
- return recent;
-}
-
bool Cainteoir::switch_voice(const rdf::uri &voice)
{
voice_metadata.add_metadata(tts_metadata, voice, rdf::tts("name"));
View
3 src/cainteoir.hpp
@@ -60,7 +60,6 @@ class Cainteoir
bool load_document(std::string filename, bool from_constructor);
void updateProgress(double elapsed, double total, double completed);
- GtkWidget *create_file_chooser_menu();
TimeBar timebar;
TocPane toc;
@@ -76,6 +75,8 @@ class Cainteoir
std::shared_ptr<VoiceSelectionView> voiceSelection;
std::shared_ptr<DocumentLibrary> library;
+ GtkWidget *library_button;
+ GtkWidget *document_button;
GtkRecentManager *recentManager;
GtkRecentFilter *recentFilter;
View
32 src/library.cpp
@@ -90,8 +90,7 @@ DocumentLibrary::DocumentLibrary(cainteoir::languages &aLanguages, GtkRecentMana
gtk_widget_set_name(view, "toc");
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
- toc_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
- gtk_tree_selection_set_mode(toc_selection, GTK_SELECTION_MULTIPLE);
+ lib_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
GtkWidget *scrolled_view = gtk_scrolled_window_new(nullptr, nullptr);
gtk_container_add(GTK_CONTAINER(scrolled_view), GTK_WIDGET(view));
@@ -111,7 +110,7 @@ DocumentLibrary::DocumentLibrary(cainteoir::languages &aLanguages, GtkRecentMana
gtk_box_pack_start(GTK_BOX(layout), topbar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(layout), scrolled_view, TRUE, TRUE, 0);
- update_recent(aRecent, aMetadata, 30);
+ update_recent(aRecent, aMetadata, 45);
}
void DocumentLibrary::update_recent(GtkRecentManager *aRecent, rdf::graph &aMetadata, int max_items_to_show)
@@ -154,3 +153,30 @@ void DocumentLibrary::update_recent(GtkRecentManager *aRecent, rdf::graph &aMeta
g_list_foreach(items, (GFunc)gtk_recent_info_unref, nullptr);
g_list_free(items);
}
+
+std::string DocumentLibrary::get_filename() const
+{
+ std::string filename;
+
+ GList *selected = gtk_tree_selection_get_selected_rows(lib_selection, nullptr);
+ if (g_list_length(selected) == 1)
+ {
+ GtkTreeModel *model = GTK_TREE_MODEL(store);
+
+ GList *item = g_list_first(selected);
+ GtkTreeIter iter;
+ if (item && gtk_tree_model_get_iter(model, &iter, (GtkTreePath *)item->data))
+ {
+ gchar *anchor = nullptr;
+ gtk_tree_model_get(model, &iter, LIB_ANCHOR, &anchor, -1);
+
+ filename = anchor;
+ g_free(anchor);
+ }
+ }
+
+ g_list_foreach(selected, (GFunc)gtk_tree_path_free, nullptr);
+ g_list_free(selected);
+
+ return filename;
+}
View
4 src/library.hpp
@@ -34,10 +34,12 @@ class DocumentLibrary
operator GtkWidget *() { return layout; }
void update_recent(GtkRecentManager *aRecent, rdf::graph &aMetadata, int max_items_to_show);
+
+ std::string get_filename() const;
private:
GtkWidget *layout;
GtkTreeStore *store;
- GtkTreeSelection *toc_selection;
+ GtkTreeSelection *lib_selection;
rdf::graph metadata;
};

0 comments on commit 9ac1115

Please sign in to comment.
Something went wrong with that request. Please try again.