static void on_configure_response(GtkDialog* dialog, gint response, gpointer user_data)
{
    if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) {
	g_print("geany complete: modified preferences\n");
	auto self = (geanycc::PythonCompletionFramework*)user_data;

	JediCompletePluginPref* pref = JediCompletePluginPref::instance();
	// suggestion window
	pref->row_text_max =
	    gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pref_widgets.row_text_max_spinbtn));

	pref->suggestion_window_height_max =
	    gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pref_widgets.swin_height_max_spinbtn));

	pref->page_up_down_skip_amount =
	    gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pref_widgets.page_up_down_skip_amount_spinbtn));
	// python
	pref->start_completion_with_dot =
	    gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_widgets.start_with_dot));

	pref->jedi_server_port =
	    gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pref_widgets.port_spinbtn));

	pref->python_path = gtk_entry_buffer_get_text(pref_widgets.pypath_buffer);

	self->save_preferences();
	self->updated_preferences();
    }
}
Example #2
0
/* This will be run if there is no config file */
static void first_run_check()
{
  /* If the configfile doesn't exist, we ask the user if he wants to save the history */
  gchar *rc_file = g_build_filename(g_get_user_config_dir(), PREFERENCES_FILE, NULL);
  /* Check if config file exists */
  if (!g_file_test(rc_file, G_FILE_TEST_EXISTS))
  {
    GtkWidget* confirm_dialog = gtk_message_dialog_new(NULL,
                                                       GTK_DIALOG_MODAL,
                                                       GTK_MESSAGE_OTHER,
                                                       GTK_BUTTONS_YES_NO,
                                                       SAVE_HIST_MESSAGE);
    gtk_window_set_title((GtkWindow*)confirm_dialog, _("Save history"));
    
    if (gtk_dialog_run((GtkDialog*)confirm_dialog) == GTK_RESPONSE_YES)
    {
      prefs.save_history = TRUE;
    } else {
      prefs.save_history = FALSE;
    }
    gtk_widget_destroy(confirm_dialog);
    /* We make sure these aren't empty */
    prefs.history_key = DEF_HISTORY_KEY;
    prefs.actions_key = DEF_ACTIONS_KEY;
    prefs.menu_key = DEF_MENU_KEY;
    prefs.search_key = DEF_SEARCH_KEY;
    prefs.offline_key = DEF_OFFLINE_KEY;
    save_preferences();
  }
  g_free(rc_file);
}
void
on_bt_prefs_save_clicked               (GtkButton       *button,
                                        gpointer         user_data)
{
  on_bt_prefs_apply_clicked( button, NULL );

  save_preferences();
}
Example #4
0
static void toggle_offline_mode() {
	if (prefs.offline_mode) {
		/* Restore clipboard contents before turning offline mode off */
		gtk_clipboard_set_text(clipboard, clipboard_text != NULL ? clipboard_text : "", -1);
	}

	prefs.offline_mode = !prefs.offline_mode;
	/* Save the change */
	save_preferences();
}
Example #5
0
/* Shows the preferences dialog on the given tab */
void show_preferences(gint tab) {
  if(gtk_grab_get_current()) {
    /* A window is already open, so we present it to the user */
    GtkWidget *toplevel = gtk_widget_get_toplevel(gtk_grab_get_current());
    gtk_window_present((GtkWindow*)toplevel);
    return;
  }
  /* Declare some variables */
  GtkWidget *frame,     *label,
            *alignment, *hbox,
            *vbox;
  
  GtkObject *adjustment, *adjustment_small, *adjustment_statics;
  GtkTreeViewColumn *tree_column;
  
  /* Create the dialog */
  GtkWidget* dialog = gtk_dialog_new_with_buttons(_("Preferences"),     NULL,
                                                   (GTK_DIALOG_MODAL  + GTK_DIALOG_NO_SEPARATOR),
                                                    GTK_STOCK_CANCEL,   GTK_RESPONSE_REJECT,
                                                    GTK_STOCK_OK,       GTK_RESPONSE_ACCEPT, NULL);
  
  gtk_window_set_icon((GtkWindow*)dialog, gtk_widget_render_icon(dialog, GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU, NULL));
  gtk_window_set_resizable((GtkWindow*)dialog, FALSE);
  
  /* Create notebook */
  GtkWidget* notebook = gtk_notebook_new();
#if GTK_CHECK_VERSION (2,14,0)
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))), notebook, TRUE, TRUE, 2);
#else
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, TRUE, TRUE, 2);
#endif
  
  /* Build the settings page */  
  GtkWidget* page_settings = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_settings, 12, 6, 12, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_settings, gtk_label_new(_("Settings")));
  GtkWidget* vbox_settings = gtk_vbox_new(FALSE, 12);
  gtk_container_add((GtkContainer*)page_settings, vbox_settings);
  
  /* Build the clipboards frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Clipboards</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  copy_check = gtk_check_button_new_with_mnemonic(_("Use _Copy (Ctrl-C)"));
  g_signal_connect((GObject*)copy_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, copy_check, FALSE, FALSE, 0);
  primary_check = gtk_check_button_new_with_mnemonic(_("Use _Primary (Selection)"));
  g_signal_connect((GObject*)primary_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, primary_check, FALSE, FALSE, 0);
  synchronize_check = gtk_check_button_new_with_mnemonic(_("S_ynchronize clipboards"));
  gtk_box_pack_start((GtkBox*)vbox, synchronize_check, FALSE, FALSE, 0);
  paste_check = gtk_check_button_new_with_mnemonic(_("_Automatically paste selected item"));
  g_signal_connect((GObject*)paste_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, paste_check, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_settings, frame, FALSE, FALSE, 0);

  /* Build the miscellaneous frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Miscellaneous</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  show_indexes_check = gtk_check_button_new_with_mnemonic(_("Show _indexes in history menu"));
  gtk_box_pack_start((GtkBox*)vbox, show_indexes_check, FALSE, FALSE, 0);
  save_uris_check = gtk_check_button_new_with_mnemonic(_("S_ave URIs"));
  gtk_box_pack_start((GtkBox*)vbox, save_uris_check, FALSE, FALSE, 0);
  hyperlinks_check = gtk_check_button_new_with_mnemonic(_("Capture _hyperlinks only"));
  gtk_box_pack_start((GtkBox*)vbox, hyperlinks_check, FALSE, FALSE, 0);
  confirm_check = gtk_check_button_new_with_mnemonic(_("C_onfirm before clearing history"));
  gtk_box_pack_start((GtkBox*)vbox, confirm_check, FALSE, FALSE, 0);
  use_rmb_menu_check = gtk_check_button_new_with_mnemonic(_("_Use right-click menu"));
  gtk_box_pack_start((GtkBox*)vbox, use_rmb_menu_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_settings, frame, FALSE, FALSE, 0);

  /* Build the history page */
  GtkWidget* page_history = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_history, 12, 6, 12, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_history, gtk_label_new(_("History")));
  GtkWidget* vbox_history = gtk_vbox_new(FALSE, 12);
  gtk_container_add((GtkContainer*)page_history, vbox_history);

  /* Build the history frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>History</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  save_check = gtk_check_button_new_with_mnemonic(_("Save _history"));
  gtk_widget_set_tooltip_text(save_check, _("Save and restore history between sessions"));
  gtk_box_pack_start((GtkBox*)vbox, save_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Items in history:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment = gtk_adjustment_new(25, 5, 1000, 1, 10, 0);
  history_spin = gtk_spin_button_new((GtkAdjustment*)adjustment, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)history_spin, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, history_spin, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Items in menu:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment_small = gtk_adjustment_new(25, 5, 100, 1, 10, 0);
  items_menu = gtk_spin_button_new((GtkAdjustment*)adjustment_small, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)items_menu, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, items_menu, FALSE, FALSE, 0);
  statics_show_check = gtk_check_button_new_with_mnemonic(_("Show _static items in menu"));
  g_signal_connect((GObject*)statics_show_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, statics_show_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Static items in menu:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment_statics = gtk_adjustment_new(10, 1, 100, 1, 10, 0);
  statics_items_spin = gtk_spin_button_new((GtkAdjustment*)adjustment_statics, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)statics_items_spin, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, statics_items_spin, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_history, frame, FALSE, FALSE, 0);

  /* Build the items frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Items</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  linemode_check = gtk_check_button_new_with_mnemonic(_("Show in a single _line"));
  gtk_box_pack_start((GtkBox*)vbox, linemode_check, FALSE, FALSE, 0);
  reverse_check = gtk_check_button_new_with_mnemonic(_("Show in _reverse order"));
  gtk_box_pack_start((GtkBox*)vbox, reverse_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Character length of items:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment = gtk_adjustment_new(50, 25, 75, 1, 5, 0);
  charlength_spin = gtk_spin_button_new((GtkAdjustment*)adjustment, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)charlength_spin, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, charlength_spin, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Omit items in the:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  ellipsize_combo = gtk_combo_box_new_text();
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Beginning"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Middle"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("End"));
  gtk_box_pack_start((GtkBox*)hbox, ellipsize_combo, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_history, frame, FALSE, FALSE, 0);
  
  /* Build the omitting frame 
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Omitting</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Omit items in the:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  ellipsize_combo = gtk_combo_box_new_text();
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Beginning"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Middle"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("End"));
  gtk_box_pack_start((GtkBox*)hbox, ellipsize_combo, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_history, frame, FALSE, FALSE, 0); */
  
  /* Build the actions page */
  GtkWidget* page_actions = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_actions, 6, 6, 6, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_actions, gtk_label_new(_("Actions")));
  GtkWidget* vbox_actions = gtk_vbox_new(FALSE, 6);
  gtk_container_add((GtkContainer*)page_actions, vbox_actions);
  
  /* Build the actions label */
  label = gtk_label_new(_("Control-click ClipIt\'s tray icon to use actions"));
  gtk_label_set_line_wrap((GtkLabel*)label, TRUE);
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)vbox_actions, label, FALSE, FALSE, 0);
  
  /* Build the actions treeview */
  GtkWidget* scrolled_window = gtk_scrolled_window_new(
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0),
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0));
  
  gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type((GtkScrolledWindow*)scrolled_window, GTK_SHADOW_ETCHED_OUT);
  GtkWidget* treeview = gtk_tree_view_new();
  gtk_tree_view_set_reorderable((GtkTreeView*)treeview, TRUE);
  gtk_tree_view_set_rules_hint((GtkTreeView*)treeview, TRUE);
  actions_list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING, -1);
  gtk_tree_view_set_model((GtkTreeView*)treeview, (GtkTreeModel*)actions_list);
  GtkCellRenderer* name_renderer = gtk_cell_renderer_text_new();
  g_object_set(name_renderer, "editable", TRUE, NULL);
  g_signal_connect((GObject*)name_renderer, "edited", (GCallback)edit_action, (gpointer)0);
  tree_column = gtk_tree_view_column_new_with_attributes(_("Action"), name_renderer, "text", 0, NULL);
  gtk_tree_view_column_set_resizable(tree_column, TRUE);
  gtk_tree_view_append_column((GtkTreeView*)treeview, tree_column);
  GtkCellRenderer* command_renderer = gtk_cell_renderer_text_new();
  g_object_set(command_renderer, "editable", TRUE, NULL);
  g_object_set(command_renderer, "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
  g_signal_connect((GObject*)command_renderer, "edited", (GCallback)edit_action, (gpointer)1);
  tree_column = gtk_tree_view_column_new_with_attributes(_("Command"), command_renderer, "text", 1, NULL);
  gtk_tree_view_column_set_expand(tree_column, TRUE);
  gtk_tree_view_append_column((GtkTreeView*)treeview, tree_column);
  gtk_container_add((GtkContainer*)scrolled_window, treeview);
  gtk_box_pack_start((GtkBox*)vbox_actions, scrolled_window, TRUE, TRUE, 0);
  
  /* Edit selection and connect treeview related signals */
  actions_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview);
  gtk_tree_selection_set_mode(actions_selection, GTK_SELECTION_BROWSE);
  g_signal_connect((GObject*)treeview, "key-press-event", (GCallback)delete_key_pressed, NULL);
  
  /* Build the buttons */
  GtkWidget* hbbox = gtk_hbutton_box_new();
  gtk_box_set_spacing((GtkBox*)hbbox, 6);
  gtk_button_box_set_layout((GtkButtonBox*)hbbox, GTK_BUTTONBOX_START);
  GtkWidget* add_button = gtk_button_new_with_label(_("Add..."));
  gtk_button_set_image((GtkButton*)add_button, gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)add_button, "clicked", (GCallback)add_action, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, add_button, FALSE, TRUE, 0);
  GtkWidget* remove_button = gtk_button_new_with_label(_("Remove"));
  gtk_button_set_image((GtkButton*)remove_button, gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)remove_button, "clicked", (GCallback)remove_action, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, remove_button, FALSE, TRUE, 0);
  GtkWidget* up_button = gtk_button_new();
  gtk_button_set_image((GtkButton*)up_button, gtk_image_new_from_stock(GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)up_button, "clicked", (GCallback)move_action_up, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, up_button, FALSE, TRUE, 0);
  GtkWidget* down_button = gtk_button_new();
  gtk_button_set_image((GtkButton*)down_button, gtk_image_new_from_stock(GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)down_button, "clicked", (GCallback)move_action_down, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, down_button, FALSE, TRUE, 0);
  gtk_box_pack_start((GtkBox*)vbox_actions, hbbox, FALSE, FALSE, 0);

  /* Build the exclude page */
  GtkWidget* page_exclude = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_exclude, 6, 6, 6, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_exclude, gtk_label_new(_("Exclude")));
  GtkWidget* vbox_exclude = gtk_vbox_new(FALSE, 6);
  gtk_container_add((GtkContainer*)page_exclude, vbox_exclude);
  
  /* Build the exclude label */
  label = gtk_label_new(_("Regex list of items that should not be inserted into the history (passwords/sites that you don't need in history, etc)."));
  gtk_label_set_line_wrap((GtkLabel*)label, TRUE);
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)vbox_exclude, label, FALSE, FALSE, 0);
  
  /* Build the exclude treeview */
  GtkWidget* scrolled_window_exclude = gtk_scrolled_window_new(
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0),
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0));
  
  gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled_window_exclude, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type((GtkScrolledWindow*)scrolled_window_exclude, GTK_SHADOW_ETCHED_OUT);
  GtkWidget* treeview_exclude = gtk_tree_view_new();
  gtk_tree_view_set_reorderable((GtkTreeView*)treeview_exclude, TRUE);
  gtk_tree_view_set_rules_hint((GtkTreeView*)treeview_exclude, TRUE);
  exclude_list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING, -1);
  gtk_tree_view_set_model((GtkTreeView*)treeview_exclude, (GtkTreeModel*)exclude_list);
  GtkCellRenderer* name_renderer_exclude = gtk_cell_renderer_text_new();
  g_object_set(name_renderer_exclude, "editable", TRUE, NULL);
  g_signal_connect((GObject*)name_renderer_exclude, "edited", (GCallback)edit_exclude, (gpointer)0);
  tree_column = gtk_tree_view_column_new_with_attributes(_("Regex"), name_renderer_exclude, "text", 0, NULL);
  gtk_tree_view_column_set_resizable(tree_column, TRUE);
  gtk_tree_view_append_column((GtkTreeView*)treeview_exclude, tree_column);
  gtk_container_add((GtkContainer*)scrolled_window_exclude, treeview_exclude);
  gtk_box_pack_start((GtkBox*)vbox_exclude, scrolled_window_exclude, TRUE, TRUE, 0);
  
  /* Edit selection and connect treeview related signals */
  exclude_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_exclude);
  gtk_tree_selection_set_mode(exclude_selection, GTK_SELECTION_BROWSE);
  g_signal_connect((GObject*)treeview_exclude, "key-press-event", (GCallback)delete_key_pressed, NULL);
  
  /* Build the buttons */
  GtkWidget* hbbox_exclude = gtk_hbutton_box_new();
  gtk_box_set_spacing((GtkBox*)hbbox_exclude, 6);
  gtk_button_box_set_layout((GtkButtonBox*)hbbox_exclude, GTK_BUTTONBOX_START);
  GtkWidget* add_button_exclude = gtk_button_new_with_label(_("Add..."));
  gtk_button_set_image((GtkButton*)add_button_exclude, gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)add_button_exclude, "clicked", (GCallback)add_exclude, NULL);
  gtk_box_pack_start((GtkBox*)hbbox_exclude, add_button_exclude, FALSE, TRUE, 0);
  GtkWidget* remove_button_exclude = gtk_button_new_with_label(_("Remove"));
  gtk_button_set_image((GtkButton*)remove_button_exclude, gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)remove_button_exclude, "clicked", (GCallback)remove_exclude, NULL);
  gtk_box_pack_start((GtkBox*)hbbox_exclude, remove_button_exclude, FALSE, TRUE, 0);
  gtk_box_pack_start((GtkBox*)vbox_exclude, hbbox_exclude, FALSE, FALSE, 0);
  
  /* Build the hotkeys page */
  GtkWidget* page_extras = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_extras, 12, 6, 12, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_extras, gtk_label_new(_("Hotkeys")));
  GtkWidget* vbox_extras = gtk_vbox_new(FALSE, 12);
  gtk_container_add((GtkContainer*)page_extras, vbox_extras);
  
  /* Build the hotkeys frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Hotkeys</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  /* History key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("History hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  history_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)history_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, history_key_entry, TRUE, TRUE, 0);
  /* Actions key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Actions hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  actions_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)actions_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, actions_key_entry, TRUE, TRUE, 0);
  /* Menu key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Menu hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  menu_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)menu_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, menu_key_entry, TRUE, TRUE, 0);
  /* Search key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Manage hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  search_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)search_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, search_key_entry, TRUE, TRUE, 0);
  /* Offline mode key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Offline mode hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  offline_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)offline_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, offline_key_entry, TRUE, TRUE, 0);
  gtk_box_pack_start((GtkBox*)vbox_extras, frame, FALSE, FALSE, 0);
  
  /* Make widgets reflect current preferences */
  gtk_toggle_button_set_active((GtkToggleButton*)copy_check, prefs.use_copy);
  gtk_toggle_button_set_active((GtkToggleButton*)primary_check, prefs.use_primary);
  gtk_toggle_button_set_active((GtkToggleButton*)synchronize_check, prefs.synchronize);
  gtk_toggle_button_set_active((GtkToggleButton*)paste_check, prefs.automatic_paste);
  gtk_toggle_button_set_active((GtkToggleButton*)show_indexes_check, prefs.show_indexes);
  gtk_toggle_button_set_active((GtkToggleButton*)save_uris_check, prefs.save_uris);
  gtk_toggle_button_set_active((GtkToggleButton*)use_rmb_menu_check, prefs.use_rmb_menu);
  gtk_toggle_button_set_active((GtkToggleButton*)save_check, prefs.save_history);
  gtk_spin_button_set_value((GtkSpinButton*)history_spin, (gdouble)prefs.history_limit);
  gtk_spin_button_set_value((GtkSpinButton*)items_menu, (gdouble)prefs.items_menu);
  gtk_toggle_button_set_active((GtkToggleButton*)statics_show_check, prefs.statics_show);
  gtk_spin_button_set_value((GtkSpinButton*)statics_items_spin, (gdouble)prefs.statics_items);
  gtk_toggle_button_set_active((GtkToggleButton*)hyperlinks_check, prefs.hyperlinks_only);
  gtk_toggle_button_set_active((GtkToggleButton*)confirm_check, prefs.confirm_clear);
  gtk_toggle_button_set_active((GtkToggleButton*)linemode_check, prefs.single_line);
  gtk_toggle_button_set_active((GtkToggleButton*)reverse_check, prefs.reverse_history);
  gtk_spin_button_set_value((GtkSpinButton*)charlength_spin, (gdouble)prefs.item_length);
  gtk_combo_box_set_active((GtkComboBox*)ellipsize_combo, prefs.ellipsize - 1);
  gtk_entry_set_text((GtkEntry*)history_key_entry, prefs.history_key);
  gtk_entry_set_text((GtkEntry*)actions_key_entry, prefs.actions_key);
  gtk_entry_set_text((GtkEntry*)menu_key_entry, prefs.menu_key);
  gtk_entry_set_text((GtkEntry*)search_key_entry, prefs.search_key);
  gtk_entry_set_text((GtkEntry*)offline_key_entry, prefs.offline_key);
  
  /* Read actions */
  read_actions();
  read_excludes();
  
  /* Run the dialog */
  gtk_widget_show_all(dialog);
#ifdef HAVE_APPINDICATOR
  gtk_widget_hide(use_rmb_menu_check);
#endif
  gtk_notebook_set_current_page((GtkNotebook*)notebook, tab);
  if (gtk_dialog_run((GtkDialog*)dialog) == GTK_RESPONSE_ACCEPT)
  {
    /* If the user disabled history saving, we ask him if he wants to delete the history file */
    if(prefs.save_history && !gtk_toggle_button_get_active((GtkToggleButton*)save_check))
      check_saved_hist_file();
    /* Apply and save preferences */
    apply_preferences();
    save_preferences();
    save_actions();
    save_excludes();
  }
  gtk_widget_destroy(dialog);
}
Example #6
0
char* get_save_filename( GtkWindow* parent, const char* cwd, char** type )
{
    char* file = NULL;
    GtkFileChooser* dlg = (GtkFileChooser*)gtk_file_chooser_dialog_new( NULL, parent,
            GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL,
            GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL );
    GSList* modules, *module;
    GtkFileFilter *filter;

    gtk_file_chooser_set_current_folder( dlg, cwd );

    GtkWidget* img = gtk_image_new();
    gtk_widget_set_size_request( img, 128, 128 );
    gtk_file_chooser_set_preview_widget( dlg, img );
    g_signal_connect( dlg, "update-preview", G_CALLBACK(on_update_preview), img );
    g_signal_connect( dlg, "notify::filter", G_CALLBACK(on_file_save_filter_changed), NULL );

    /*
    /// TODO: determine file type from file name
    filter = gtk_file_filter_new();
    gtk_file_filter_set_name( filter, _("Determined by File Name") );
    gtk_file_filter_add_pixbuf_formats( filter );
    gtk_file_chooser_add_filter( dlg, filter );
    */

    modules = gdk_pixbuf_get_formats();
    for( module = modules; module; module = module->next )
    {
        char *name, *desc, *tmp;
        char **exts, **mimes, **mime;

        GdkPixbufFormat* format = (GdkPixbufFormat*)module->data;
        if( ! gdk_pixbuf_format_is_writable( format ) )
            continue;

        filter = gtk_file_filter_new();

        name = gdk_pixbuf_format_get_name( format );
        desc = gdk_pixbuf_format_get_description( format );
        exts = gdk_pixbuf_format_get_extensions( format );
        mimes = gdk_pixbuf_format_get_mime_types( format );
        tmp = g_strdup_printf( "%s (*.%s)", desc, exts[0], NULL );

        g_object_set_data_full(G_OBJECT(filter), "type", name, (GDestroyNotify)g_free);
        g_strfreev(exts);
        g_free( desc );
        gtk_file_filter_set_name( filter, tmp );
        g_free( tmp );

        for( mime  = mimes; *mime ; ++mime )
            gtk_file_filter_add_mime_type( filter, *mime );
        g_strfreev( mimes );
        gtk_file_chooser_add_filter( dlg, filter );
    }
    g_slist_free( modules );

    int initial_jpg_quality = pref.jpg_quality;
    int initial_png_compression = pref.png_compression;

    if( gtk_dialog_run( (GtkDialog*)dlg ) == GTK_RESPONSE_OK )
    {
        filter = gtk_file_chooser_get_filter( dlg );
        file = gtk_file_chooser_get_filename( dlg );
        *type = g_object_steal_data(G_OBJECT(filter), "type");

        if( !*type )   // auto detection
        {
            /// TODO: auto file type
        }
        else
        {
            /* TODO: append appropriate extension if needed. */
        }
    }
    gtk_widget_destroy( (GtkWidget*)dlg );

    if ((initial_jpg_quality != pref.jpg_quality) || (initial_png_compression != pref.png_compression))
        save_preferences();

    return file;
}
Example #7
0
int main(int argc, char *argv[]) {
    GtkBuilder *builder;
    GString *txt = g_string_new_len("", 20);
    char filepad[100];
    unsigned short i, mask=0;
    GdkScreen* screen = NULL;
	int xx, yy, screen_width, screen_height;

	InitAudio();

	pad = get_real_path();					// get the path of the executable

	sprintf(filepad, "%s/.lock", pad);
	setlock(filepad, 10, TRUE);				// disable multiple instances for at least 10 seconds

	g_thread_init (NULL);

    display = XOpenDisplay(0);
    if (display == NULL)
        exit(1);

    gtk_set_locale();

    gtk_init(&argc, &argv);

    builder = gtk_builder_new ();

    sprintf(filepad, "%s/%s.glade", pad, SKIN);

    gtk_builder_add_from_file(builder, filepad, NULL);

    gtk_builder_connect_signals (builder, NULL);

    // set widgets to be handled by the event handlers
    window 			= GW ("window");
    preferences 	= GW ("preferences");
    lookup		 	= GW ("lookup");
    fontbutton 		= GW ("fontbutton1");
    drag 			= GW ("dragbar");
    debug 			= GW ("debug");
	papier 			= GW ("drawingarea1");
    colorbutton1 	= GW ("colorbutton1");
    colorbutton2 	= GW ("colorbutton2");
    checkbutton1	= GW ("checkbutton1");
    entry1 			= GW ("entry1");
    entry2 			= GW ("entry2");
    gtktable1 		= GW ("table1");
    checkbutton8	= GW ("checkbutton8");
    checkbutton9	= GW ("checkbutton9");
    textview1 		= GW ("textview1");
    entry16 		= GW ("entry16");
    combobox1 		= GW ("combobox1");
    scrolled		= GW ("scrolledwindow2");
    opacity 		= GTK_ADJUSTMENT (gtk_builder_get_object (builder, "adjustment1"));
    speed 			= GTK_ADJUSTMENT (gtk_builder_get_object (builder, "adjustment2"));
    textbuffer1		= GTK_TEXT_BUFFER(gtk_builder_get_object (builder, "textbuffer1"));

	for (i=0; i<sizeof(unsigned short); i++) {	// set each bit of mask
		mask <<= 8;
		mask |= 0xFF;
	}

	// fill the struct that keeps the 7 recognize buttons & checkboxes (in preferences)
    for (i=0; i<7; i++) {
    	g_string_sprintf(txt, "checkbutton%d", i+2);
		modebits[i].check = GTK_WIDGET(gtk_builder_get_object (builder, txt->str));
		g_string_sprintf(txt, "button%d", i+3);
		modebits[i].button = GTK_WIDGET(gtk_builder_get_object (builder, txt->str));
		switch (i) {
			case 0: modebits[i].bit = (GB1|GB2);	modebits[i].mask = ((GB1|GB2) ^ mask);	break;
			case 1: modebits[i].bit = BIG5;			modebits[i].mask = (BIG5 ^ mask);		break;
			case 2: modebits[i].bit = DIGITS;		modebits[i].mask = (DIGITS ^ mask);		break;
			case 3: modebits[i].bit = LOWERCASE;	modebits[i].mask = (LOWERCASE ^ mask);	break;
			case 4: modebits[i].bit = UPPERCASE;	modebits[i].mask = (UPPERCASE ^ mask);	break;
			case 5: modebits[i].bit = PUNC;			modebits[i].mask = (PUNC ^ mask);		break;
			case 6: modebits[i].bit = DEFAULT;		modebits[i].mask = (DEFAULT ^ mask);	break;
		}
	}

	// fill the structure that keeps the 13 labels for the keys (preferences)
    for (i=0; i<13; i++) {
    	g_string_sprintf(txt, "button%d", i+10);
		conf.defkey[i].button = GTK_WIDGET(gtk_builder_get_object (builder, txt->str));
    	g_string_sprintf(txt, "entry%d", i+3);
		conf.defkey[i].entry = GTK_WIDGET(gtk_builder_get_object (builder, txt->str));
		conf.defkey[i].key = 0;
    }

    // place a simple combobox for the input selection (preferences)
    combo = gtk_combo_box_new_text();
    gtk_table_attach_defaults(GTK_TABLE(gtktable1), combo, 1, 2, 2, 3);
    gtk_widget_show (combo);

    // get events and labels for the 9 candidates
    for (int i=0; i< 9; i++) {
        g_string_sprintf(txt, "knop%d", i+1);
        knop[i] = GTK_WIDGET (gtk_builder_get_object (builder, txt->str));
        g_string_sprintf(txt, "event%d", i+1);
        event[i] = GTK_WIDGET (gtk_builder_get_object (builder, txt->str));
    }

    // set events for paste and backspace entries (preferences)
    g_signal_connect(entry1, "key_press_event", G_CALLBACK(on_key_press), NULL);
    g_signal_connect(entry1, "key_release_event", G_CALLBACK(on_key_release), NULL);
    g_signal_connect(entry2, "key_press_event", G_CALLBACK(on_key_press), NULL);
    g_signal_connect(entry2, "key_release_event", G_CALLBACK(on_key_release), NULL);

    if (!create_wtpen_window())
        exit(1);

    wtpen_init();

	g_object_unref (G_OBJECT (builder));

    gtk_widget_show_all(GTK_WIDGET(window));

	for (i=0; i<NUMKEYS; i++)	hotkey[i] = 0;	// reset all hotkeys

    // load cedict from file
    sprintf(filepad, "%s/data", pad);
    import_cedict(filepad);

    // load settings from file
    sprintf(filepad, "%s/xpen.cfg", pad);
    load_preferences(filepad);

    // set background and shape
    sprintf(filepad, "%s/%s.png", pad, SKIN);
    set_window_shape(filepad);

	// some styles to be used in the cedict browser (lookup window)δΈ€
	gtk_text_buffer_create_tag(textbuffer1, "mark", "background", "yellow", "foreground", "black", NULL);
	gtk_text_buffer_create_tag(textbuffer1, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
	gtk_text_buffer_create_tag(textbuffer1, "character", "font", conf.font, "scale", 1.3, NULL);
	gtk_text_buffer_create_tag(textbuffer1, "translation", "scale", 0.9, NULL);
	gtk_text_buffer_create_tag(textbuffer1, "pinyin", "scale", 1.1, NULL);

    ready = TRUE;	// let_configure_event() know that it can start its setup

	// start monitoring system-wide keypresses
	g_thread_create (intercept_key_thread, NULL, FALSE, NULL);

	// make sure the window positions and size are legal
	screen = gtk_window_get_screen(GTK_WINDOW(window));		// get screen size
	screen_width = gdk_screen_get_width(screen);
	screen_height = gdk_screen_get_height(screen);

    xx = MAX(MIN(screen_width-width, conf.x), 0);			// set the position of the main window
    yy = MAX(MIN(screen_height-height, conf.y), 0);
	gtk_widget_set_uposition(window, xx, yy);

    xx = MIN(screen_width, conf.dx);						// set the size of the lookup window
    yy = MIN(screen_height, conf.dy);
	gtk_widget_set_usize(lookup, xx, yy);

	xx = MAX(MIN(screen_width-conf.dx, conf.lx), 0);		// set the position of the lookup window
	yy = MAX(MIN(screen_height-conf.dy, conf.ly), 0);
	gtk_widget_set_uposition(lookup, xx, yy);

	g_timeout_add (100, checkfocus, NULL);	// check the inputfocus (each 1/10s)

//////////////////////////////////////////////////////////////
//on_full_screen_button_pressed();	// start the full screen mode
//////////////////////////////////////////////////////////////

    gtk_main();						// start the main loop

	sprintf(filepad, "%s/.lock", pad);		// remove the lock
	setlock(filepad, 0, FALSE);

	// save all settings to file
    sprintf(filepad, "%s/xpen.cfg", pad);
	save_preferences (filepad);

    g_free(pad);
	free_all();

    wtpen_window_done();
    wtlib_done();

    SDL_CloseAudio();
    SDL_Quit();

//on_full_screen_button_pressed();

    return 0;
}
Example #8
0
/* FIXME: Cleanup track refs */
void common_cleanup(struct con_win *cwin)
{
	CDEBUG(DBG_INFO, "Cleaning up");

	if ((cwin->cstate->state == ST_STOPPED) && (cwin->cstate->curr_mobj_clear))
		delete_musicobject(cwin->cstate->curr_mobj);

	if ((cwin->cstate->state == ST_PLAYING) || (cwin->cstate->state == ST_PAUSED))
		stop_playback(cwin);

	save_preferences(cwin);

	g_object_unref(cwin->library_store);
	g_object_unref(cwin->pixbuf->image_play);
	g_object_unref(cwin->pixbuf->image_pause);

	if (cwin->pixbuf->pixbuf_app)
		g_object_unref(cwin->pixbuf->pixbuf_app);
	if (cwin->pixbuf->pixbuf_dir)
		g_object_unref(cwin->pixbuf->pixbuf_dir);
	if (cwin->pixbuf->pixbuf_artist)
		g_object_unref(cwin->pixbuf->pixbuf_artist);
	if (cwin->pixbuf->pixbuf_album)
		g_object_unref(cwin->pixbuf->pixbuf_album);
	if (cwin->pixbuf->pixbuf_track)
		g_object_unref(cwin->pixbuf->pixbuf_track);
	if (cwin->pixbuf->pixbuf_genre)
		g_object_unref(cwin->pixbuf->pixbuf_genre);

	g_slice_free(struct pixbuf, cwin->pixbuf);

	if (cwin->album_art)
		gtk_widget_destroy(cwin->album_art);

	if (cwin->cstate->cdda_drive)
		cdio_cddap_close(cwin->cstate->cdda_drive);
	if (cwin->cstate->cddb_disc)
		cddb_disc_destroy(cwin->cstate->cddb_disc);
	if (cwin->cstate->cddb_conn) {
		cddb_destroy(cwin->cstate->cddb_conn);
		libcddb_shutdown();
	}

	g_free(cwin->cpref->lw.lastfm_user);
	g_free(cwin->cpref->lw.lastfm_pass);
#ifdef HAVE_LIBGLYR
	g_free(cwin->cpref->cache_folder);
#endif
	g_free(cwin->cpref->configrc_file);
	g_free(cwin->cpref->installed_version);
	g_free(cwin->cpref->audio_sink);
	g_free(cwin->cpref->audio_alsa_device);
	g_free(cwin->cpref->audio_oss_device);
	g_free(cwin->cpref->album_art_pattern);
	g_free(cwin->cpref->audio_cd_device);
	g_free(cwin->cpref->start_mode);
	g_free(cwin->cpref->sidebar_pane);
	g_key_file_free(cwin->cpref->configrc_keyfile);
	free_str_list(cwin->cpref->library_dir);
	free_str_list(cwin->cpref->lib_add);
	free_str_list(cwin->cpref->lib_delete);
	free_str_list(cwin->cpref->library_tree_nodes);
	free_str_list(cwin->cpref->playlist_columns);
	g_slist_free(cwin->cpref->playlist_column_widths);
	g_slice_free(struct con_pref, cwin->cpref);

	g_rand_free(cwin->cstate->rand);
	g_free(cwin->cstate->last_folder);
	g_mutex_free(cwin->cstate->c_mutex);

	/* Hack, hack */
	if (g_mutex_trylock(cwin->cstate->l_mutex) == TRUE) {
		g_mutex_unlock(cwin->cstate->l_mutex);
		g_mutex_free(cwin->cstate->l_mutex);
	}
	g_cond_free(cwin->cstate->c_cond);
	g_slice_free(struct con_state, cwin->cstate);

#ifdef HAVE_LIBGLYR
	uninit_glyr_related (cwin);
#endif
	g_free(cwin->cdbase->db_file);
	sqlite3_close(cwin->cdbase->db);
	g_slice_free(struct con_dbase, cwin->cdbase);

	if (cwin->cstate->audio_init && cwin->cmixer)
		cwin->cmixer->deinit_mixer(cwin);
	if (cwin->clibao->ao_dev) {
		CDEBUG(DBG_INFO, "Freeing ao dev");
		ao_close(cwin->clibao->ao_dev);
	}
	ao_shutdown();
	g_slice_free(struct con_mixer, cwin->cmixer);
	g_slice_free(struct con_libao, cwin->clibao);

	g_free(cwin->clastfm->session_id);
	g_free(cwin->clastfm->submission_url);
	if (cwin->clastfm->curl_handle)
		curl_easy_cleanup(cwin->clastfm->curl_handle);
	curl_global_cleanup();
	g_slice_free(struct con_lastfm, cwin->clastfm);

	dbus_connection_remove_filter(cwin->con_dbus,
				      dbus_filter_handler,
				      cwin);
	dbus_bus_remove_match(cwin->con_dbus,
			      "type='signal',path='/org/pragha/DBus'",
			      NULL);
	dbus_connection_unref(cwin->con_dbus);

	#if HAVE_GLIB_2_26
	mpris_cleanup(cwin);
	#endif

	if (notify_is_initted())
		notify_uninit();

	#ifdef HAVE_LIBKEYBINDER
	keybinder_unbind("XF86AudioPlay", (KeybinderHandler) keybind_play_handler);
	keybinder_unbind("XF86AudioStop", (KeybinderHandler) keybind_stop_handler);
	keybinder_unbind("XF86AudioPrev", (KeybinderHandler) keybind_prev_handler);
	keybinder_unbind("XF86AudioNext", (KeybinderHandler) keybind_next_handler);
	keybinder_unbind("XF86AudioMedia", (KeybinderHandler) keybind_media_handler);
	#endif

	g_option_context_free(cwin->cmd_context);

	g_slice_free(struct con_win, cwin);
}
Example #9
0
int main(int argc, char *argv[])
{
    GError *error = NULL;
    GOptionContext *context;
    MainWin* win;

#ifdef ENABLE_NLS
    bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR );
    bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" );
    textdomain ( GETTEXT_PACKAGE );
#endif

    context = g_option_context_new ("- simple image viewer");
    g_option_context_add_main_entries (context, opt_entries, GETTEXT_PACKAGE);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    if ( !g_option_context_parse (context, &argc, &argv, &error) )
    {
        g_print( "option parsing failed: %s\n", error->message);
        return 1;
    }

    if( should_display_version )
    {
        printf( "gpicview %s\n", VERSION );
        return 0;
    }

    gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), PIXMAP_DIR);

    load_preferences();

    /* Allocate and show the window.
     * We must show the window now in case the file open needs to put up an error dialog. */
    win = (MainWin*)main_win_new();
    gtk_widget_show( GTK_WIDGET(win) );

    if ( pref.open_maximized )
        gtk_window_maximize( (GtkWindow*)win );

    // FIXME: need to process multiple files...
    if( files )
    {
        if( G_UNLIKELY( *files[0] != '/' && strstr( files[0], "://" )) )    // This is an URI
        {
            char* path = g_filename_from_uri( files[0], NULL, NULL );
            main_win_open( win, path, ZOOM_NONE );
            g_free( path );
        }
        else
            main_win_open( win, files[0], ZOOM_NONE );

        if (should_start_slideshow)
            main_win_start_slideshow ( win );
    }
    else
    {
        main_win_open( win, ".", ZOOM_NONE );
    }

    gtk_main();

    save_preferences();

    return 0;
}