diff options
| -rw-r--r-- | gui/viewtorrents.glade | 68 | ||||
| -rw-r--r-- | src/main.c | 58 |
2 files changed, 106 insertions, 20 deletions
diff --git a/gui/viewtorrents.glade b/gui/viewtorrents.glade index 98ffaba..c83ba36 100644 --- a/gui/viewtorrents.glade +++ b/gui/viewtorrents.glade @@ -5,18 +5,20 @@ <object class="GtkAccelGroup" id="accelgroup1"/> <object class="GtkActionGroup" id="actiongroup"> <child> - <object class="GtkAction" id="connectaction"> - <property name="label" translatable="yes">Connect</property> - <property name="tooltip" translatable="yes">Connect to rTorrent</property> - <property name="stock_id">gtk-connect</property> + <object class="GtkAction" id="rehashaction"> + <property name="label" translatable="yes">Rehash</property> + <property name="tooltip" translatable="yes">Rehash selected torrent</property> + <property name="stock_id">gtk-refresh</property> </object> + <accelerator key="r" modifiers="GDK_CONTROL_MASK"/> </child> <child> - <object class="GtkAction" id="disconnectaction"> - <property name="label" translatable="yes">Disconnect</property> - <property name="tooltip" translatable="yes">Disconnect from rTorrent</property> - <property name="stock_id">gtk-disconnect</property> + <object class="GtkAction" id="stopaction"> + <property name="label" translatable="yes">Stop</property> + <property name="tooltip" translatable="yes">Stop selected torrent</property> + <property name="stock_id">gtk-media-stop</property> </object> + <accelerator key="d" modifiers="GDK_CONTROL_MASK"/> </child> <child> <object class="GtkAction" id="startaction"> @@ -27,20 +29,18 @@ <accelerator key="s" modifiers="GDK_CONTROL_MASK"/> </child> <child> - <object class="GtkAction" id="stopaction"> - <property name="label" translatable="yes">Stop</property> - <property name="tooltip" translatable="yes">Stop selected torrent</property> - <property name="stock_id">gtk-media-stop</property> + <object class="GtkAction" id="disconnectaction"> + <property name="label" translatable="yes">Disconnect</property> + <property name="tooltip" translatable="yes">Disconnect from rTorrent</property> + <property name="stock_id">gtk-disconnect</property> </object> - <accelerator key="d" modifiers="GDK_CONTROL_MASK"/> </child> <child> - <object class="GtkAction" id="rehashaction"> - <property name="label" translatable="yes">Rehash</property> - <property name="tooltip" translatable="yes">Rehash selected torrent</property> - <property name="stock_id">gtk-refresh</property> + <object class="GtkAction" id="connectaction"> + <property name="label" translatable="yes">Connect</property> + <property name="tooltip" translatable="yes">Connect to rTorrent</property> + <property name="stock_id">gtk-connect</property> </object> - <accelerator key="r" modifiers="GDK_CONTROL_MASK"/> </child> </object> <object class="GtkAboutDialog" id="aboutdialog"> @@ -739,4 +739,36 @@ If authentication is needed, enter username and password as well.</property> <action-widget response="-5">button1</action-widget> </action-widgets> </object> + <object class="GtkMenu" id="torrentmenu"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="accel_group">accelgroup1</property> + <child> + <object class="GtkImageMenuItem" id="menuitem5"> + <property name="related_action">startaction</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_stock">True</property> + <property name="accel_group">accelgroup1</property> + </object> + </child> + <child> + <object class="GtkImageMenuItem" id="menuitem6"> + <property name="related_action">stopaction</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_stock">True</property> + <property name="accel_group">accelgroup1</property> + </object> + </child> + <child> + <object class="GtkImageMenuItem" id="menuitem7"> + <property name="related_action">rehashaction</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_stock">True</property> + <property name="accel_group">accelgroup1</property> + </object> + </child> + </object> </interface> @@ -65,6 +65,7 @@ typedef struct GtkAction* connectaction, * disconnectaction; GtkAction* startaction, * stopaction, * rehashaction; GtkCheckMenuItem* viewtoolbaritem; + GtkWidget* torrentmenu; GtkToolbar* toolbar; @@ -264,6 +265,10 @@ static void do_start(GtkAction* action, gpointer data); static void do_stop(GtkAction* action, gpointer data); static void do_rehash(GtkAction* action, gpointer data); +static gboolean do_popupmenu(GtkWidget* treeview, gpointer data); +static gboolean do_buttonpressed(GtkWidget *treeview, GdkEventButton *event, + gpointer data); + static void do_viewtoolbaritem(GtkCheckMenuItem* checkmenuitem, gpointer data); static void do_about(GtkMenuItem* menuitem, gpointer data); @@ -296,6 +301,7 @@ int main(int argc, char** argv) GtkWidget* pwddlg; GtkCellRenderer* cell; GtkTreeViewColumn* column; + GtkWidget* treeview; GThread* worker; worker_data_t worker_data; master_t master; @@ -402,12 +408,18 @@ int main(int argc, char** argv) gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(master.liststore), liststore_default_compare_func, &master, NULL); - master.listselection = gtk_tree_view_get_selection( - GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"))); + master.torrentmenu = GTK_WIDGET(gtk_builder_get_object(builder, + "torrentmenu")); + treeview = GTK_WIDGET(gtk_builder_get_object(builder, "treeview")); + master.listselection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); gtk_tree_selection_set_mode(master.listselection, GTK_SELECTION_SINGLE); g_signal_connect(master.listselection, "changed", G_CALLBACK(listselection_changed), &master); + g_signal_connect(treeview, "button-press-event", + G_CALLBACK(do_buttonpressed), &master); + g_signal_connect(treeview, "popup-menu", G_CALLBACK(do_popupmenu), &master); + cell = custom_cell_renderer_state_new(); column = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder, "statecolumn")); @@ -563,6 +575,7 @@ int main(int argc, char** argv) gtk_widget_destroy(master.top); gtk_widget_destroy(pwddlg); gtk_widget_destroy(master.connectdlg); + gtk_widget_destroy(master.torrentmenu); g_object_unref(builder); g_key_file_free(master.config); @@ -2302,3 +2315,44 @@ void do_about(GtkMenuItem* G_GNUC_UNUSED menuitem, gpointer data) master_t* master = data; gtk_widget_show_all(master->aboutdlg); } + +static void view_contextmenu(GtkWidget* treeview, GdkEventButton* event, + gpointer data) +{ + master_t* master = data; + gtk_widget_show_all(master->torrentmenu); + gtk_menu_popup(GTK_MENU(master->torrentmenu), NULL, NULL, NULL, NULL, + event ? event->button : 0, + gdk_event_get_time((GdkEvent*)event)); +} + +gboolean do_popupmenu(GtkWidget* treeview, gpointer data) +{ + view_contextmenu(treeview, NULL, data); + return TRUE; +} + +gboolean do_buttonpressed(GtkWidget *treeview, GdkEventButton *event, + gpointer data) +{ + if (event->type == GDK_BUTTON_PRESS && event->button == 3) + { + master_t* master = data; + GtkTreePath *path; + + if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), + (gint)event->x, + (gint)event->y, + &path, NULL, NULL, NULL)) + { + gtk_tree_selection_unselect_all(master->listselection); + gtk_tree_selection_select_path(master->listselection, path); + gtk_tree_path_free(path); + } + + view_contextmenu(treeview, event, data); + return TRUE; + } + + return FALSE; +} |
