Exemple #1
0
/* Called when status icon is control-clicked */
static gboolean show_actions_menu(gpointer data) {
  /* Declare some variables */
  GtkWidget *menu,       *menu_item,
            *menu_image, *item_label;

  /* Create menu */
  menu = gtk_menu_new();
  g_signal_connect((GObject*)menu, "selection-done", (GCallback)gtk_widget_destroy, NULL);
  /* Actions using: */
  menu_item = gtk_image_menu_item_new_with_label(_("Actions using:"));
  menu_image = gtk_image_new_from_stock(GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU);
  gtk_image_menu_item_set_image((GtkImageMenuItem*)menu_item, menu_image);
  g_signal_connect((GObject*)menu_item, "select", (GCallback)gtk_menu_item_deselect, NULL);
  gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
  /* Clipboard contents */
  gchar* text = gtk_clipboard_wait_for_text(clipboard);
  if (text != NULL)
  {
    menu_item = gtk_menu_item_new_with_label(_("None"));
    /* Modify menu item label properties */
    item_label = gtk_bin_get_child((GtkBin*)menu_item);
    gtk_label_set_single_line_mode((GtkLabel*)item_label, TRUE);
    gtk_label_set_ellipsize((GtkLabel*)item_label, prefs.ellipsize);
    gtk_label_set_width_chars((GtkLabel*)item_label, 30);
    /* Making bold... */
    gchar* bold_text = g_markup_printf_escaped("<b>%s</b>", text);
    gtk_label_set_markup((GtkLabel*)item_label, bold_text);
    g_free(bold_text);
    /* Append menu item */
    g_signal_connect((GObject*)menu_item, "select", (GCallback)gtk_menu_item_deselect, NULL);
    gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
  }
  else
  {
    /* Create menu item for empty clipboard contents */
    menu_item = gtk_menu_item_new_with_label(_("None"));
    /* Modify menu item label properties */
    item_label = gtk_bin_get_child((GtkBin*)menu_item);
    gtk_label_set_markup((GtkLabel*)item_label, _("<b>None</b>"));
    /* Append menu item */
    g_signal_connect((GObject*)menu_item, "select", (GCallback)gtk_menu_item_deselect, NULL);

    gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
  }
  /* -------------------- */
  gtk_menu_shell_append((GtkMenuShell*)menu, gtk_separator_menu_item_new());
  /* Actions */
  gchar* path = g_build_filename(g_get_user_data_dir(), ACTIONS_FILE, NULL);
  FILE* actions_file = fopen(path, "rb");
  g_free(path);
  /* Check that it opened and begin read */
  if (actions_file)
  {
    gint size;
    size_t fread_return;
    fread_return = fread(&size, 4, 1, actions_file);
    /* Check if actions file is empty */
    if (!size)
    {
      /* File contained no actions so adding empty */
      menu_item = gtk_menu_item_new_with_label(_("Empty"));
      gtk_widget_set_sensitive(menu_item, FALSE);
      gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
    }
    /* Continue reading items until size is 0 */
    while (size)
    {
      /* Read name */
      gchar* name = (gchar*)g_malloc(size + 1);
      fread_return = fread(name, size, 1, actions_file);
      name[size] = '\0';
      menu_item = gtk_menu_item_new_with_label(name);
      g_free(name);
      fread_return = fread(&size, 4, 1, actions_file);
      /* Read command */
      gchar* command = (gchar*)g_malloc(size + 1);
      fread_return = fread(command, size, 1, actions_file);
      command[size] = '\0';
      fread_return = fread(&size, 4, 1, actions_file);
      /* Append the action */
      gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
      g_signal_connect((GObject*)menu_item,        "activate",
                       (GCallback)action_selected, (gpointer)command);
    }
    fclose(actions_file);
  }
  else
  {
    /* File did not open so adding empty */
    menu_item = gtk_menu_item_new_with_label(_("Empty"));
    gtk_widget_set_sensitive(menu_item, FALSE);
    gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
  }
  /* -------------------- */
  gtk_menu_shell_append((GtkMenuShell*)menu, gtk_separator_menu_item_new());
  /* Edit actions */
  menu_item = gtk_image_menu_item_new_with_mnemonic(_("_Edit actions"));
  menu_image = gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
  gtk_image_menu_item_set_image((GtkImageMenuItem*)menu_item, menu_image);
  g_signal_connect((GObject*)menu_item, "activate", (GCallback)edit_actions_selected, NULL);
  gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
  /* Popup the menu... */
  gtk_widget_show_all(menu);
  gtk_menu_popup((GtkMenu*)menu, NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time());
  /* Return false so the g_timeout_add() function is called only once */
  return FALSE;
}
Exemple #2
0
void linphone_gtk_call_log_update(GtkWidget *w){
	GtkTreeView *v=GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view"));
	GtkTreeStore *store;
	const MSList *logs;
	GtkTreeSelection *select;
	GtkWidget *notebook=linphone_gtk_get_widget(w,"viewswitch");
	gint nb;

	store=(GtkTreeStore*)gtk_tree_view_get_model(v);
	if (store==NULL){
		store=gtk_tree_store_new(3,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_POINTER,G_TYPE_STRING);
		gtk_tree_view_set_model(v,GTK_TREE_MODEL(store));
		g_object_unref(G_OBJECT(store));
		fill_renderers(GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view")));
		select=gtk_tree_view_get_selection(v);
		gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
		g_signal_connect_swapped(G_OBJECT(select),"changed",(GCallback)call_log_selection_changed,v);
		g_signal_connect(G_OBJECT(notebook),"focus-tab",(GCallback)linphone_gtk_call_log_reset_missed_call,NULL);
		g_signal_connect(G_OBJECT(v),"button-press-event",(GCallback)linphone_gtk_call_log_button_pressed,NULL);
	}
	nb=linphone_core_get_missed_calls_count(linphone_gtk_get_core());
	if(nb > 0)
		linphone_gtk_call_log_display_missed_call(nb);
	gtk_tree_store_clear (store);

	for (logs=linphone_core_get_call_logs(linphone_gtk_get_core());logs!=NULL;logs=logs->next){
		LinphoneCallLog *cl=(LinphoneCallLog*)logs->data;
		GtkTreeIter iter, iter2;
		LinphoneAddress *la=linphone_call_log_get_dir(cl)==LinphoneCallIncoming ? linphone_call_log_get_from(cl) : linphone_call_log_get_to(cl);
		char *addr= linphone_address_as_string(la);
		const char *display;
		gchar *logtxt, *headtxt, *minutes, *seconds;
		gchar quality[20];
		const char *status=NULL;
		gchar *start_date=NULL;
		LinphoneFriend *lf=NULL;
		int duration=linphone_call_log_get_duration(cl);
		time_t start_date_time=linphone_call_log_get_start_date(cl);
		const gchar *call_status_icon_name;

#if GLIB_CHECK_VERSION(2,30,0) // The g_date_time_format function exists since 2.26.0 but the '%c' format is only supported since 2.30.0
		if (start_date_time){
			GDateTime *dt=g_date_time_new_from_unix_local(start_date_time);
			start_date=g_date_time_format(dt,"%c");
			g_date_time_unref(dt);
		}
#else
		start_date=g_strdup(ctime(&start_date_time));
		if (start_date[strlen(start_date) - 1] == '\n') {
			start_date[strlen(start_date) - 1] = '\0';
		}
#endif
		lf=linphone_core_get_friend_by_address(linphone_gtk_get_core(),addr);
		if(lf != NULL){
			/*update display name from friend*/
			display = linphone_friend_get_name(lf);
			if (display != NULL) linphone_address_set_display_name(la, display);
		} else {
			display=linphone_address_get_display_name(la);
		}
		if (display==NULL){
			display=linphone_address_get_username (la);
			if (display==NULL){
				display=linphone_address_get_domain (la);
			}
		}

		if (linphone_call_log_get_quality(cl)!=-1){
			snprintf(quality,sizeof(quality),"%.1f",linphone_call_log_get_quality(cl));
		}else snprintf(quality,sizeof(quality)-1,"%s",_("n/a"));
		switch(linphone_call_log_get_status(cl)){
			case LinphoneCallAborted:
				status=_("Aborted");
			break;
			case LinphoneCallMissed:
				status=_("Missed");
			break;
			case LinphoneCallDeclined:
				status=_("Declined");
			break;
			default:
			break;
		}
		minutes=g_markup_printf_escaped(
			ngettext("%i minute", "%i minutes", duration/60),
			duration/60);
		seconds=g_markup_printf_escaped(
			ngettext("%i second", "%i seconds", duration%60),
			duration%60);
		if (status==NULL) {
				headtxt=g_markup_printf_escaped("<big><b>%s</b></big>\t%s",display,start_date ? start_date : "");
				logtxt=g_markup_printf_escaped(
				_("<small><i>%s</i>\t"
				  "<i>Quality: %s</i></small>\n%s\t%s\t"),
				addr, quality, minutes, seconds);
		} else {
			headtxt=g_markup_printf_escaped(_("<big><b>%s</b></big>\t%s"),display,start_date ? start_date : "");
			logtxt=g_markup_printf_escaped(
			"<small><i>%s</i></small>\t"
				"\n%s",addr, status);
		}
		g_free(minutes);
		g_free(seconds);
		if (start_date) g_free(start_date);
		gtk_tree_store_append (store,&iter,NULL);
		call_status_icon_name = linphone_call_log_get_dir(cl) == LinphoneCallOutgoing ?
			"linphone-call-status-outgoing" : "linphone-call-status-incoming";
		gtk_tree_store_set (store,&iter,
		               0, call_status_icon_name,
		               1, headtxt,2,cl,-1);
		gtk_tree_store_append (store,&iter2,&iter);
		gtk_tree_store_set (store,&iter2,1,logtxt,-1);
		ms_free(addr);
		g_free(logtxt);
		g_free(headtxt);
	}
}
Exemple #3
0
GtkWidget *
nm_mb_menu_item_new (const char *connection_name,
                     guint32 strength,
                     const char *provider,
                     guint32 technology,
                     guint32 state,
                     gboolean enabled,
                     NMApplet *applet)
{
	NMMbMenuItem *item;
	NMMbMenuItemPrivate *priv;
	const char *tech_name;

	item = g_object_new (NM_TYPE_MB_MENU_ITEM, NULL);
	if (!item)
		return NULL;

	priv = NM_MB_MENU_ITEM_GET_PRIVATE (item);
	priv->int_strength = strength;

	/* Construct the description string */
	tech_name = get_tech_name (technology);
	switch (state) {
	default:
	case MB_STATE_UNKNOWN:
		priv->desc_string = g_strdup (_("not enabled"));
		break;
	case MB_STATE_IDLE:
		if (connection_name)
			priv->desc_string = g_strdup (connection_name);
		else
			priv->desc_string = g_strdup (_("not registered"));
		break;
	case MB_STATE_HOME:
		if (connection_name) {
			if (provider && tech_name)
				priv->desc_string = g_strdup_printf ("%s (%s %s)", connection_name, provider, tech_name);
			else if (provider || tech_name)
				priv->desc_string = g_strdup_printf ("%s (%s)", connection_name, provider ? provider : tech_name);
			else
				priv->desc_string = g_strdup_printf ("%s", connection_name);
		} else {
			if (provider) {
				if (tech_name)
					priv->desc_string = g_strdup_printf ("%s %s", provider, tech_name);
				else
					priv->desc_string = g_strdup_printf ("%s", provider);
			} else {
				if (tech_name)
					priv->desc_string = g_strdup_printf (_("Home network (%s)"), tech_name);
				else
					priv->desc_string = g_strdup_printf (_("Home network"));
			}
		}
		break;
	case MB_STATE_SEARCHING:
		if (connection_name)
			priv->desc_string = g_strdup (connection_name);
		else
			priv->desc_string = g_strdup (_("searching"));
		break;
	case MB_STATE_DENIED:
		priv->desc_string = g_strdup (_("registration denied"));
		break;
	case MB_STATE_ROAMING:
		if (connection_name) {
			if (tech_name)
				priv->desc_string = g_strdup_printf (_("%s (%s roaming)"), connection_name, tech_name);
			else
				priv->desc_string = g_strdup_printf (_("%s (roaming)"), connection_name);
		} else {
			if (provider) {
				if (tech_name)
					priv->desc_string = g_strdup_printf (_("%s (%s roaming)"), provider, tech_name);
				else
					priv->desc_string = g_strdup_printf (_("%s (roaming)"), provider);
			} else {
				if (tech_name)
					priv->desc_string = g_strdup_printf (_("Roaming network (%s)"), tech_name);
				else
					priv->desc_string = g_strdup_printf (_("Roaming network"));
			}
		}
		break;
	}

	/* Assume a connection name means the label should be active */
	if (enabled && connection_name) {
		char *markup;

		gtk_label_set_use_markup (GTK_LABEL (priv->desc), TRUE);
		markup = g_markup_printf_escaped ("<b>%s</b>", priv->desc_string);
		gtk_label_set_markup (GTK_LABEL (priv->desc), markup);
		g_free (markup);
		gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
	} else {
		/* Disconnected and disabled states */
		gtk_label_set_use_markup (GTK_LABEL (priv->desc), FALSE);
		gtk_label_set_text (GTK_LABEL (priv->desc), priv->desc_string);
		gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
	}

	/* And the strength icon, if we have strength information at all */
	if (enabled && strength) {
		gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength),
		                           mobile_helper_get_quality_icon (strength, applet));
	}

	return GTK_WIDGET (item);
}
Exemple #4
0
static void
editor_inline_spelling_suggestions (GtkhtmlEditor *editor,
                                    GtkhtmlSpellChecker *checker)
{
	GtkActionGroup *action_group;
	GtkUIManager *manager;
	GtkHTML *html;
	GList *list;
	const gchar *path;
	gchar *word;
	guint count = 0;
	guint length;
	guint merge_id;
	guint threshold;

	html = gtkhtml_editor_get_html (editor);
	word = html_engine_get_spell_word (html->engine);
	list = gtkhtml_spell_checker_get_suggestions (checker, word, -1);

	path = "/context-menu/context-spell-suggest/";
	manager = gtkhtml_editor_get_ui_manager (editor);
	action_group = editor->priv->suggestion_actions;
	merge_id = editor->priv->spell_suggestions_merge_id;

	/* Calculate how many suggestions to put directly in the
	 * context menu.  The rest will go in a secondary menu. */
	length = g_list_length (list);
	if (length <= MAX_LEVEL1_SUGGESTIONS)
		threshold = length;
	else if (length - MAX_LEVEL1_SUGGESTIONS < MIN_LEVEL2_SUGGESTIONS)
		threshold = length;
	else
		threshold = MAX_LEVEL1_SUGGESTIONS;

	while (list != NULL) {
		gchar *suggestion = list->data;
		gchar *action_name;
		gchar *action_label;
		GtkAction *action;
		GtkWidget *child;
		GSList *proxies;

		/* Once we reach the threshold, put all subsequent
		 * spelling suggestions in a secondary menu. */
		if (count == threshold)
			path = "/context-menu/context-more-suggestions-menu/";

		/* Action name just needs to be unique. */
		action_name = g_strdup_printf ("suggest-%d", count++);

		action_label = g_markup_printf_escaped (
			"<b>%s</b>", suggestion);

		action = gtk_action_new (
			action_name, action_label, NULL, NULL);

		g_object_set_data_full (
			G_OBJECT (action), "word",
			g_strdup (suggestion), g_free);

		g_signal_connect (
			action, "activate", G_CALLBACK (
			action_context_spell_suggest_cb), editor);

		gtk_action_group_add_action (action_group, action);

		gtk_ui_manager_add_ui (
			manager, merge_id, path,
			action_name, action_name,
			GTK_UI_MANAGER_AUTO, FALSE);

		/* XXX GtkAction offers no support for Pango markup,
		 *     so we have to manually set "use-markup" on the
		 *     child of the proxy widget. */
		gtk_ui_manager_ensure_update (manager);
		proxies = gtk_action_get_proxies (action);
		child = gtk_bin_get_child (proxies->data);
		g_object_set (child, "use-markup", TRUE, NULL);

		g_free (suggestion);
		g_free (action_name);
		g_free (action_label);

		list = g_list_delete_link (list, list);
	}

	g_free (word);
}
void sensor_config_dialog_create(SensorsApplet *sensors_applet) {
	GtkTreeModel *model;
	GtkTreeIter iter;

        SensorConfigDialog *config_dialog;

        GtkListStore *icon_store;
        IconType count;
        GdkPixbuf *pixbuf;

        GdkColor graph_color;        
        gchar *sensor_label;
        gchar *header_text;
        
	/* instance variables for data */
	gdouble low_value, high_value, multiplier, offset;
	gboolean alarm_enable;
	gchar *low_alarm_command, *high_alarm_command;
	gint alarm_timeout;
        IconType icon_type;
        gchar *graph_color_string;

        config_dialog = g_new0(SensorConfigDialog, 1);
        config_dialog->sensors_applet = sensors_applet;

	gtk_tree_selection_get_selected(sensors_applet->selection,
					&model,
					&iter);
	/* get current values of alarm and its enable */
	gtk_tree_model_get(model, &iter,
			   LOW_VALUE_COLUMN, &low_value,
			   HIGH_VALUE_COLUMN, &high_value,
			   ALARM_ENABLE_COLUMN, &alarm_enable,
			   LOW_ALARM_COMMAND_COLUMN, &low_alarm_command,
                           HIGH_ALARM_COMMAND_COLUMN, &high_alarm_command,
			   ALARM_TIMEOUT_COLUMN, &alarm_timeout,
			   MULTIPLIER_COLUMN, &multiplier,
			   OFFSET_COLUMN, &offset,
                           ICON_TYPE_COLUMN, &icon_type,
                           GRAPH_COLOR_COLUMN, &graph_color_string,
                           LABEL_COLUMN, &sensor_label,
			   -1);
        header_text = g_strdup_printf("%s - %s", _("Sensor Properties"), sensor_label);

	config_dialog->dialog = gtk_dialog_new_with_buttons(header_text,
                                                            GTK_WINDOW(sensors_applet->prefs_dialog->dialog),
                                                            GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
                                                            GTK_STOCK_HELP,
                                                            GTK_RESPONSE_HELP,
                                                            GTK_STOCK_CLOSE,
                                                            GTK_RESPONSE_CLOSE,
                                                            NULL);
        
        g_free(header_text);
        g_free(sensor_label);

	g_object_set(config_dialog->dialog,
		     "border-width", 12,
		     NULL);
	
	g_signal_connect(config_dialog->dialog,
                         "response",
                         G_CALLBACK(sensor_config_dialog_response),
                         config_dialog);
	
	
        /* graph stuff */
        header_text = g_markup_printf_escaped("<b>%s</b>", _("Graph"));
        config_dialog->graph_header = g_object_new(GTK_TYPE_LABEL,
                                   "use-markup", TRUE,
                                   "label", header_text,
                                   "xalign", 0.0,
                                   NULL);
        g_free(header_text);


        gdk_color_parse(graph_color_string,
                        &graph_color);
        
        config_dialog->graph_color_button = GTK_COLOR_BUTTON(gtk_color_button_new_with_color(&graph_color));
	config_dialog->graph_color_button_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
                                                  "child", config_dialog->graph_color_button,
                                                   "xalign", 0.0,
                                                   "xscale", 0.0,
                                                   NULL);

        gtk_color_button_set_title(config_dialog->graph_color_button, _("Graph Color"));
        
        config_dialog->graph_color_label = g_object_new(GTK_TYPE_LABEL,
                                         "label", _("Graph _color"),
					"mnemonic-widget", config_dialog->graph_color_button,
					"use-underline", TRUE,
					"xalign", 0.0,
					NULL);

	g_signal_connect(config_dialog->graph_color_button, "color-set", 
                         G_CALLBACK(sensor_config_dialog_graph_color_set), 
                         config_dialog);

        /* icon stuff */
        header_text = g_markup_printf_escaped("<b>%s</b>", _("Icon"));
        config_dialog->icon_header = g_object_new(GTK_TYPE_LABEL,
                                   "use-markup", TRUE,
                                   "label", header_text,
                                   "xalign", 0.0,
                                   NULL);
        g_free(header_text);

        /* icon type */
        icon_store = gtk_list_store_new(1, GDK_TYPE_PIXBUF);

        /* populate list with icons */
        for (count = CPU_ICON; count < NUM_ICONS; count++) {
                pixbuf = sensors_applet_load_icon(count);
                if (pixbuf) {
                        gtk_list_store_insert(icon_store, &iter, count);
                        gtk_list_store_set(icon_store, &iter,
                                           0, pixbuf,
                                           -1);
                        /* let list hold icons */
                        g_object_unref(pixbuf);
                }
        }
        
        config_dialog->icon_type_combo_box = GTK_COMBO_BOX(gtk_combo_box_new_with_model(GTK_TREE_MODEL(icon_store)));

	config_dialog->icon_type_combo_box_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
                                                   "child", config_dialog->icon_type_combo_box,
                                                   "xalign", 0.0,
                                                   "xscale", 0.0,
                                                   NULL);

        config_dialog->icon_renderer = gtk_cell_renderer_pixbuf_new();
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(config_dialog->icon_type_combo_box),
                                   GTK_CELL_RENDERER(config_dialog->icon_renderer),
                                   FALSE);

        gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(config_dialog->icon_type_combo_box),
                                      GTK_CELL_RENDERER(config_dialog->icon_renderer),
                                      "pixbuf", 0);

        gtk_combo_box_set_active(config_dialog->icon_type_combo_box,
                                 icon_type);

	g_signal_connect(config_dialog->icon_type_combo_box, "changed", 
                         G_CALLBACK(sensor_config_dialog_icon_type_changed), 
                         config_dialog);


        
        config_dialog->icon_type_label = g_object_new(GTK_TYPE_LABEL,
 					"label", _("Sensor _icon"),
					"mnemonic-widget", config_dialog->icon_type_combo_box,
					"use-underline", TRUE,
					"xalign", 0.0,
					NULL);

        header_text = g_markup_printf_escaped("<b>%s</b>", _("Scaling Parameters"));
        config_dialog->scale_header = g_object_new(GTK_TYPE_LABEL,
                                   "use-markup", TRUE,
                                   "label", header_text,
                                   "xalign", 0.0,
                                   NULL);
        g_free(header_text);

	/* do multiplier and offset widgets */
	config_dialog->multiplier_adjust = g_object_new(GTK_TYPE_ADJUSTMENT,
			      "value", 1.0,
			      "lower", 0.001,
			      "upper", 1000.0,
			      "step-increment", 0.1,
			      "page-increment", 1.0,
			      "page-size", 1.0,
			      NULL);

	
	config_dialog->multiplier_spinbutton = g_object_new(GTK_TYPE_SPIN_BUTTON,
					     "adjustment", config_dialog->multiplier_adjust,
					     "digits", VALUE_DECIMAL_PLACES,
					     "value", multiplier,
					     "width-chars", SPINBUTTON_WIDTH_CHARS,
					     NULL);

	config_dialog->multiplier_spinbutton_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
						     "child", config_dialog->multiplier_spinbutton,
						     "xalign", 0.0,
						     "xscale", 0.0,
						     NULL);

	config_dialog->multiplier_label = g_object_new(GTK_TYPE_LABEL,
                                                       "label", _("Sensor value _multiplier"),
                                                       "mnemonic-widget", config_dialog->multiplier_spinbutton,
                                                       "use-underline", TRUE,
                                                       "xalign", 0.0,
                                                       NULL);
	
	
	g_signal_connect(config_dialog->multiplier_spinbutton, "value-changed", G_CALLBACK(sensor_config_dialog_multiplier_changed), config_dialog);
	

	config_dialog->offset_adjust = g_object_new(GTK_TYPE_ADJUSTMENT,
				     "value", 0.0,
				     "lower", -1000.000,
				     "upper", 1000.000,
				     "step-increment", 0.01,
				     "page-increment", 1.0,
				     "page-size", 1.0,
				     NULL);

	config_dialog->offset_spinbutton = g_object_new(GTK_TYPE_SPIN_BUTTON,
					 "adjustment", config_dialog->offset_adjust,
					 "digits", VALUE_DECIMAL_PLACES,
					 "value", (gdouble)offset,
					 "width-chars", SPINBUTTON_WIDTH_CHARS,
					 NULL);
	
	config_dialog->offset_spinbutton_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
						 "child", config_dialog->offset_spinbutton,
						 "xalign", 0.0,
						 "xscale", 0.0,
						 NULL);

	config_dialog->offset_label = g_object_new(GTK_TYPE_LABEL,
				    "label", _("Sensor value _offset"),
				    "mnemonic-widget", config_dialog->offset_spinbutton,
				    "use-underline", TRUE,
				    "xalign", 0.0,
				    NULL);

	g_signal_connect(config_dialog->offset_spinbutton, "value-changed", G_CALLBACK(sensor_config_dialog_offset_changed), config_dialog);


        /* now do alarm widgets */
        header_text = g_markup_printf_escaped("<b>%s</b>", _("Sensor Limits"));
        config_dialog->limits_header = g_object_new(GTK_TYPE_LABEL,
                                                    "use-markup", TRUE,
                                                    "label", header_text,
                                                    "xalign", 0.0,
                                                    NULL);
        g_free(header_text);

	config_dialog->low_value_adjust = g_object_new(GTK_TYPE_ADJUSTMENT,
                                        "value", 0.0,
                                        "lower", -100000.0,
                                        "upper", 100000.0,
                                        "step-increment", 1.0,
                                        "page-increment", 10.0,
                                        "page-size", 100.0,
                                        NULL);

	
	config_dialog->low_value_spinbutton = g_object_new(GTK_TYPE_SPIN_BUTTON,
                                                           "adjustment", config_dialog->low_value_adjust,
                                                           "digits", VALUE_DECIMAL_PLACES,
                                                           "value", low_value,
                                                           "width-chars", SPINBUTTON_WIDTH_CHARS,

					      NULL);
	
	config_dialog->low_value_spinbutton_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
					  "child", config_dialog->low_value_spinbutton,
					  "xalign", 0.0,
					  "xscale", 0.0,
					  NULL);

	config_dialog->low_value_label = g_object_new(GTK_TYPE_LABEL,
                                                      "label", _("Sensor _low value"),
                                                      "mnemonic-widget", config_dialog->low_value_spinbutton,
                                                      "use-underline", TRUE,
                                                      "xalign", 0.0,

					 NULL);

	
	g_signal_connect(config_dialog->low_value_spinbutton, "value-changed", G_CALLBACK(sensor_config_dialog_low_value_changed), config_dialog);

	config_dialog->high_value_adjust = g_object_new(GTK_TYPE_ADJUSTMENT,
			      "value", 0.0,
			      "lower", -100000.0,
			      "upper", 100000.0,
			      "step-increment", 1.0,
			      "page-increment", 10.0,
			      "page-size", 100.0,
			      NULL);

	
	config_dialog->high_value_spinbutton = g_object_new(GTK_TYPE_SPIN_BUTTON,
                                                            "adjustment", config_dialog->high_value_adjust,
                                                            "digits", VALUE_DECIMAL_PLACES,
                                                            "value", high_value,
                                                            "width-chars", SPINBUTTON_WIDTH_CHARS,

                                                            NULL);
	
	config_dialog->high_value_spinbutton_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
                                                                    "child", config_dialog->high_value_spinbutton,
                                                                    "xalign", 0.0,
                                                                    "xscale", 0.0,
                                                                    NULL);
        
	config_dialog->high_value_label = g_object_new(GTK_TYPE_LABEL,
                                                       "label", _("Sensor _high value"),
                                                       "mnemonic-widget", config_dialog->high_value_spinbutton,
                                                       "use-underline", TRUE,
                                                       "xalign", 0.0,

                                                       NULL);
        
	
	g_signal_connect(config_dialog->high_value_spinbutton, "value-changed", G_CALLBACK(sensor_config_dialog_high_value_changed), config_dialog);
	

        header_text = g_markup_printf_escaped("<b>%s</b>", _("Alarm"));
        config_dialog->alarm_header = g_object_new(GTK_TYPE_LABEL,
                                   "use-markup", TRUE,
                                   "label", header_text,
                                   "xalign", 0.0,
                                   NULL);
        g_free(header_text);

	config_dialog->alarm_timeout_adjust = g_object_new(GTK_TYPE_ADJUSTMENT,
					    "value", 0.0,
					    "lower", 0.0,
					    "upper", 10000.0,
					    "step-increment", 1.0,
					    "page-increment", 10.0,
					    "page-size", 100.0,
					    NULL);

	config_dialog->alarm_timeout_spinbutton = g_object_new(GTK_TYPE_SPIN_BUTTON,
                                                               "adjustment", config_dialog->alarm_timeout_adjust,
                                                               "digits", 0,
                                                               "value", (gdouble)alarm_timeout,
                                                               "width-chars", SPINBUTTON_WIDTH_CHARS,
                                                               "sensitive", alarm_enable,

						NULL);
	config_dialog->alarm_timeout_spinbutton_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
							"child", config_dialog->alarm_timeout_spinbutton,
							"xalign", 0.0,
							"xscale", 0.0,
							NULL);
	
	config_dialog->alarm_timeout_label = g_object_new(GTK_TYPE_LABEL,
                                                          "label", _("Alarm _repeat interval (secs)"),
                                                          "mnemonic-widget", config_dialog->alarm_timeout_spinbutton,
                                                          
                                                          "use-underline", TRUE,
                                                          "xalign", 0.0,
                                                          "sensitive", alarm_enable,
                                                          NULL);

	g_signal_connect(config_dialog->alarm_timeout_spinbutton, "value-changed", G_CALLBACK(sensor_config_dialog_alarm_timeout_changed), config_dialog);

	config_dialog->low_alarm_command_entry = g_object_new(GTK_TYPE_ENTRY,
                                                              "text", low_alarm_command,
                                                              "width-chars", 25,
                                                              "sensitive", alarm_enable,
                                                              NULL);

	g_free(low_alarm_command);

	config_dialog->low_alarm_command_label = g_object_new(GTK_TYPE_LABEL,
                                                          "use-underline", TRUE,
                                                          "label", _("Lo_w alarm command"),
                                                          "mnemonic-widget", config_dialog->low_alarm_command_entry,
                                                          "xalign", 0.0,
                                                          "sensitive", alarm_enable,

                                                          NULL);

	g_signal_connect(config_dialog->low_alarm_command_entry,
			 "changed",
			 G_CALLBACK(sensor_config_dialog_low_alarm_command_edited),
			 config_dialog);

	config_dialog->high_alarm_command_entry = g_object_new(GTK_TYPE_ENTRY,
                                                              "text", high_alarm_command,
                                                              "width-chars", 25,
                                                              "sensitive", alarm_enable,
                                                              NULL);

	g_free(high_alarm_command);

	config_dialog->high_alarm_command_label = g_object_new(GTK_TYPE_LABEL,
                                                          "use-underline", TRUE,
                                                          "label", _("Hi_gh alarm command"),
                                                          "mnemonic-widget", config_dialog->high_alarm_command_entry,
                                                          "xalign", 0.0,
                                                          "sensitive", alarm_enable,

                                                          NULL);

	g_signal_connect(config_dialog->high_alarm_command_entry,
			 "changed",
			 G_CALLBACK(sensor_config_dialog_high_alarm_command_edited),
			 config_dialog);

	config_dialog->alarm_enable_checkbutton = g_object_new(GTK_TYPE_CHECK_BUTTON,
						"use-underline", TRUE,
						"label", _("_Enable alarm"),
						"active", alarm_enable,
						"xalign", 0.0,
						NULL);
	
	config_dialog->alarm_enable_aligner = g_object_new(GTK_TYPE_ALIGNMENT,
					    "child", config_dialog->alarm_enable_checkbutton,
					    "xalign", 0.0,
					    "xscale", 0.0,
					    NULL);

	g_signal_connect(config_dialog->alarm_enable_checkbutton, "toggled", G_CALLBACK(sensor_config_dialog_alarm_toggled), config_dialog);
	


        config_dialog->size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
        gtk_size_group_add_widget(config_dialog->size_group,
                                  GTK_WIDGET(config_dialog->multiplier_spinbutton));
        gtk_size_group_add_widget(config_dialog->size_group,
                                  GTK_WIDGET(config_dialog->offset_spinbutton));
        gtk_size_group_add_widget(config_dialog->size_group,
                                  GTK_WIDGET(config_dialog->low_value_spinbutton));
        gtk_size_group_add_widget(config_dialog->size_group,
                                  GTK_WIDGET(config_dialog->high_value_spinbutton));
        gtk_size_group_add_widget(config_dialog->size_group,
                                  GTK_WIDGET(config_dialog->alarm_timeout_spinbutton));
        gtk_size_group_add_widget(config_dialog->size_group,
                                  GTK_WIDGET(config_dialog->icon_type_combo_box));
        gtk_size_group_add_widget(config_dialog->size_group,
                                  GTK_WIDGET(config_dialog->graph_color_button));
        g_object_unref(config_dialog->size_group);

	config_dialog->table = g_object_new(GTK_TYPE_TABLE,
			     "column-spacing", 5,
			     "homogeneous", FALSE,
			     "n-columns", 3,
			     "n-rows", 15,
                             "row-spacing", 6,
                             "column-spacing", 12,
			     NULL);


        gtk_table_attach_defaults(config_dialog->table,
                                  GTK_WIDGET(config_dialog->scale_header),
                                  0, 2,
                                  0, 1);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->multiplier_label),
				  1, 2,
				  1, 2);
	
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->multiplier_spinbutton_aligner),
				  2, 3,
				  1, 2);
	
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->offset_label),
				  1, 2,
				  2, 3);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->offset_spinbutton_aligner),
				  2, 3,
				  2, 3);
	
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->limits_header),
				  0, 2,
				  3, 4);

	/* now pack alarm widgets */
        gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->low_value_label),
				  1, 2,
				  4, 5);
	
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->low_value_spinbutton_aligner),
				  2, 3,
				  4, 5);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->high_value_label),
				  1, 2,
				  5, 6);
	
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->high_value_spinbutton_aligner),
				  2, 3,
				  5, 6);
	
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->alarm_header),
				  0, 2,
				  6, 7);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->alarm_enable_aligner),
				  1, 2,
				  7, 8);	

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->alarm_timeout_label),
				  1, 2,
				  8, 9);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->alarm_timeout_spinbutton_aligner),
				  2, 3,
				  8, 9);
	
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->low_alarm_command_label),
				  1, 2,
				  9, 10);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->low_alarm_command_entry),
				  2, 3,
				  9, 10);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->high_alarm_command_label),
				  1, 2,
				  10, 11);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->high_alarm_command_entry),
				  2, 3,
				  10, 11);

        gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->icon_header),
				  0, 2,
				  11, 12);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->icon_type_label),
				  1, 2,
				  12, 13);
	
        gtk_table_attach_defaults(config_dialog->table,
                                  GTK_WIDGET(config_dialog->icon_type_combo_box_aligner),
                                  2, 3,
                                  12, 13);
        
	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->graph_header),
				  0, 2,
				  13, 14);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->graph_color_label),
				  1, 2,
				  14, 15);

	gtk_table_attach_defaults(config_dialog->table,
				  GTK_WIDGET(config_dialog->graph_color_button_aligner),
				  2, 3,
				  14, 15);

	gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(config_dialog->dialog)->vbox), GTK_WIDGET(config_dialog->table));
	gtk_widget_show_all(config_dialog->dialog);

}		
Exemple #6
0
gint
main (gint argc,
      gchar **argv)
{
	GTask *task;
	GCancellable *cancellable;
	gchar *file = NULL, *oper = NULL;
	const gchar *title = NULL;
	gint ii;
	GError *error = NULL;

#ifdef G_OS_WIN32
	e_util_win32_initialize ();
#endif

	bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	gtk_init_with_args (
		&argc, &argv, NULL, options, GETTEXT_PACKAGE, &error);

	if (error != NULL) {
		g_printerr ("%s\n", error->message);
		g_error_free (error);
		exit (EXIT_FAILURE);
	}

	if (opt_remaining != NULL) {
		for (ii = 0; ii < g_strv_length (opt_remaining); ii++) {
			if (backup_op) {
				title = _("Evolution Back Up");
				oper = _("Backing up to the file %s");
				bk_file = g_strdup ((gchar *) opt_remaining[ii]);
				file = bk_file;
			} else if (restore_op) {
				title = _("Evolution Restore");
				oper = _("Restoring from the file %s");
				res_file = g_strdup ((gchar *) opt_remaining[ii]);
				file = res_file;
			} else if (check_op) {
				d (g_message ("Checking %s", (gchar *) opt_remaining[ii]));
				chk_file = g_strdup ((gchar *) opt_remaining[ii]);
			}
		}
	}

	cancellable = g_cancellable_new ();

	if (gui_arg && !check_op) {
		GtkWidget *widget, *container;
		GtkWidget *action_area;
		GtkWidget *content_area;
		const gchar *txt, *txt2;
		gchar *str = NULL;
		gchar *markup;

		gtk_window_set_default_icon_name ("evolution");

		/* Backup / Restore only can have GUI.
		 * We should restrict the rest. */
		progress_dialog = gtk_dialog_new_with_buttons (
			title, NULL,
			GTK_DIALOG_MODAL,
			_("_Cancel"), GTK_RESPONSE_REJECT,
			NULL);

		gtk_container_set_border_width (
			GTK_CONTAINER (progress_dialog), 12);

		action_area = gtk_dialog_get_action_area (
			GTK_DIALOG (progress_dialog));
		content_area = gtk_dialog_get_content_area (
			GTK_DIALOG (progress_dialog));

		/* Override GtkDialog defaults */
		gtk_box_set_spacing (GTK_BOX (content_area), 12);
		gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
		gtk_box_set_spacing (GTK_BOX (action_area), 12);
		gtk_container_set_border_width (GTK_CONTAINER (action_area), 0);

		if (oper && file)
			str = g_strdup_printf (oper, file);

		container = gtk_grid_new ();
		gtk_grid_set_column_spacing (GTK_GRID (container), 6);
		gtk_grid_set_row_spacing (GTK_GRID (container), 0);
		gtk_widget_show (container);

		gtk_box_pack_start (
			GTK_BOX (content_area), container, FALSE, TRUE, 0);

		widget = gtk_image_new_from_icon_name (
			"edit-copy", GTK_ICON_SIZE_DIALOG);
		gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
		gtk_widget_show (widget);

		gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 3);
		g_object_set (
			G_OBJECT (widget),
			"halign", GTK_ALIGN_FILL,
			"valign", GTK_ALIGN_FILL,
			"vexpand", TRUE,
			NULL);

		if (backup_op) {
			txt = _("Backing up Evolution Data");
			txt2 = _("Please wait while Evolution is backing up your data.");
		} else if (restore_op) {
			txt = _("Restoring Evolution Data");
			txt2 = _("Please wait while Evolution is restoring your data.");
		} else {
			g_return_val_if_reached (EXIT_FAILURE);
		}

		markup = g_markup_printf_escaped ("<b><big>%s</big></b>", txt);
		widget = gtk_label_new (markup);
		gtk_label_set_line_wrap (GTK_LABEL (widget), FALSE);
		gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
		gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
		gtk_widget_show (widget);
		g_free (markup);

		gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 1, 1);
		g_object_set (
			G_OBJECT (widget),
			"halign", GTK_ALIGN_FILL,
			"hexpand", TRUE,
			"valign", GTK_ALIGN_FILL,
			NULL);

		markup = g_strconcat (
			txt2, " ", _("This may take a while depending "
			"on the amount of data in your account."), NULL);
		widget = gtk_label_new (markup);
		gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
		gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
		gtk_widget_show (widget);
		g_free (markup);

		gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1);
		g_object_set (
			G_OBJECT (widget),
			"halign", GTK_ALIGN_FILL,
			"hexpand", TRUE,
			"valign", GTK_ALIGN_FILL,
			NULL);

		pbar = gtk_progress_bar_new ();

		if (str != NULL) {
			markup = g_markup_printf_escaped ("<i>%s</i>", str);
			widget = gtk_label_new (markup);
			gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
			gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
			g_free (markup);
			g_free (str);

			gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
			g_object_set (
				G_OBJECT (widget),
				"halign", GTK_ALIGN_FILL,
				"hexpand", TRUE,
				"valign", GTK_ALIGN_FILL,
				NULL);

			gtk_grid_attach (GTK_GRID (container), pbar, 1, 3, 1, 1);
		} else
			gtk_grid_attach (GTK_GRID (container), pbar, 1, 2, 1, 1);

		g_object_set (
			G_OBJECT (pbar),
			"halign", GTK_ALIGN_FILL,
			"hexpand", TRUE,
			"valign", GTK_ALIGN_FILL,
			NULL);

		g_signal_connect (
			progress_dialog, "response",
			G_CALLBACK (dlg_response), cancellable);
		gtk_widget_show_all (progress_dialog);

	} else if (check_op) {
		/* For sanity we don't need gui */
		check (chk_file, NULL);
		exit (result == 0 ? 0 : 1);
	}

	if (gui_arg) {
		e_named_timeout_add_full (
			G_PRIORITY_DEFAULT,
			50, pbar_update,
			g_object_ref (cancellable),
			(GDestroyNotify) g_object_unref);
	}

	task = g_task_new (cancellable, cancellable, NULL, NULL);
	g_task_run_in_thread (task, start_job);
	g_object_unref (task);

	gtk_main ();

	g_object_unref (cancellable);
	e_util_cleanup_settings ();

	return result;
}
Exemple #7
0
static void about_create(void)
{
	GtkWidget *vbox1;
	GtkWidget *image;	
 	GtkWidget *vbox2;
	GtkWidget *label;
	GtkWidget *button;
	GtkWidget *scrolledwin;
	GtkWidget *notebook;
	GtkWidget *table;
	char *markup;
	GtkWidget *confirm_area;
	GtkWidget *close_button;
	static GdkGeometry geometry;

	stats_text_buffer = NULL;

	window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "about");
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
	gtk_window_set_title(GTK_WINDOW(window), _("About Claws Mail"));
	gtk_container_set_border_width(GTK_CONTAINER(window), 8);
	gtk_widget_set_size_request(window, -1, -1);
	g_signal_connect(G_OBJECT(window), "size_allocate",
			 G_CALLBACK(about_size_allocate_cb), NULL);
	g_signal_connect(G_OBJECT(window), "size_allocate",
			 G_CALLBACK(about_size_allocate_cb), NULL);
	g_signal_connect(G_OBJECT(window), "delete_event",
			 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
	g_signal_connect(G_OBJECT(window), "key_press_event",
			 G_CALLBACK(key_pressed), NULL);
	
	if (!geometry.min_width) {
		geometry.min_width = 450;
		geometry.min_height = 500;
	}

	gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
				      GDK_HINT_MIN_SIZE);
	gtk_window_set_default_size(GTK_WINDOW(window), prefs_common.aboutwin_width,
				    prefs_common.aboutwin_height);	
	
	gtk_widget_realize(window);

	vbox1 = gtk_vbox_new(FALSE, 8);
	gtk_container_add(GTK_CONTAINER(window), vbox1);

	table = gtk_table_new (2, 1, FALSE);
	gtk_box_pack_start(GTK_BOX(vbox1), table,
			FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (table), 8);
	gtk_table_set_row_spacings (GTK_TABLE (table), 8);
	gtk_table_set_col_spacings (GTK_TABLE (table), 8);

	image = stock_pixmap_widget(window, STOCK_PIXMAP_CLAWS_MAIL_LOGO);
	gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 1,
			(GtkAttachOptions) (GTK_EXPAND),
			(GtkAttachOptions) (0), 0, 0);

	vbox2 = gtk_vbox_new (FALSE, 4);
	gtk_table_attach (GTK_TABLE (table), vbox2, 1, 2, 0, 1,
			(GtkAttachOptions) (GTK_EXPAND),
			(GtkAttachOptions) (0), 0, 0);

	label = gtk_label_new("");
	gtk_label_set_selectable(GTK_LABEL(label), TRUE);
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
	gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
	markup = g_markup_printf_escaped
		("<span weight=\"bold\" size=\"xx-large\">Claws Mail</span>\nversion %s",
		 VERSION_GIT_FULL);
	gtk_label_set_markup(GTK_LABEL(label), markup);
	g_free(markup);

	button = gtkut_get_link_btn(window, HOMEPAGE_URI, " "HOMEPAGE_URI" ");
	gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0);
#ifndef GENERIC_UMPC
	label = gtk_label_new
		(_("Copyright (C) 1999-2015\nThe Claws Mail Team\n"
		 "and Hiroyuki Yamamoto"));
	gtk_label_set_selectable(GTK_LABEL(label), TRUE);
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
	gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
#endif
	notebook = gtk_notebook_new();
	gtk_widget_set_size_request(notebook, -1, 220);
	gtk_widget_show(notebook);

	if ((scrolledwin = about_create_child_page_info()) != NULL) {
		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				scrolledwin,
				gtk_label_new_with_mnemonic(_("_Info")));
	}

	if ((scrolledwin = about_create_child_page_authors()) != NULL) {
		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				scrolledwin,
				gtk_label_new_with_mnemonic(_("_Authors")));
	}

	if ((scrolledwin = about_create_child_page_features()) != NULL) {
		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				scrolledwin,
				gtk_label_new_with_mnemonic(_("_Features")));
	}

	if ((scrolledwin = about_create_child_page_license()) != NULL) {
		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				scrolledwin,
				gtk_label_new_with_mnemonic(_("_License")));
	}

	if (release_notes_available() &&
			(scrolledwin = about_create_child_page_release_notes()) != NULL) {

		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				scrolledwin,
				gtk_label_new_with_mnemonic(_("_Release Notes")));
	}

	if ((scrolledwin = about_create_child_page_session_stats()) != NULL) {
		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				scrolledwin,
				gtk_label_new_with_mnemonic(_("_Statistics")));
	}

	gtk_box_pack_start(GTK_BOX(vbox1), notebook, TRUE, TRUE, 0);

	gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
				      NULL, NULL, NULL, NULL);
	gtk_box_pack_end(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 4);
	gtk_widget_grab_default(close_button);
	gtk_widget_grab_focus(close_button);
	g_signal_connect_closure
		(G_OBJECT(close_button), "clicked",
		 g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
				     window, NULL), FALSE);

	gtk_widget_show_all(window);
}
GtkWidget *
gedit_io_loading_error_message_area_new (const gchar         *uri,
					 const GeditEncoding *encoding,
					 const GError        *error)
{
	gchar *error_message = NULL;
	gchar *message_details = NULL;
	gchar *full_formatted_uri;
	gchar *encoding_name;
	gchar *uri_for_display;
	gchar *temp_uri_for_display;
	GtkWidget *message_area;
	gboolean edit_anyway = FALSE;
	gboolean convert_error = FALSE;
	
	g_return_val_if_fail (uri != NULL, NULL);
	g_return_val_if_fail (error != NULL, NULL);
	g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) ||
			      (error->domain == GEDIT_DOCUMENT_ERROR) ||
			      (error->domain == G_IO_ERROR), NULL);
	
	full_formatted_uri = gedit_utils_uri_for_display (uri);

	/* Truncate the URI so it doesn't get insanely wide. Note that even
	 * though the dialog uses wrapped text, if the URI doesn't contain
	 * white space then the text-wrapping code is too stupid to wrap it.
	 */
	temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri,
								MAX_URI_IN_DIALOG_LENGTH);
	g_free (full_formatted_uri);
	
	uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
	g_free (temp_uri_for_display);

	if (encoding != NULL)
		encoding_name = gedit_encoding_to_string (encoding);
	else
		encoding_name = g_strdup ("UTF-8");

	if (is_gio_error (error, G_IO_ERROR_TOO_MANY_LINKS))
	{
		message_details = g_strdup (_("The number of followed links is limited and the actual file could not be found within this limit."));
	}
	else if (is_gio_error (error, G_IO_ERROR_PERMISSION_DENIED))
	{
		message_details = g_strdup (_("You do not have the permissions necessary to open the file."));
	}
	else if ((is_gio_error (error, G_IO_ERROR_INVALID_DATA) && encoding == NULL) ||
	         (error->domain == GEDIT_DOCUMENT_ERROR &&
	         error->code == GEDIT_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED))
	{
		message_details = g_strconcat (_("gedit has not been able to detect "
					         "the character encoding."), "\n",
					       _("Please check that you are not trying to open a binary file."), "\n",
					       _("Select a character encoding from the menu and try again."), NULL);
		convert_error = TRUE;
	}
	else if (error->domain == GEDIT_DOCUMENT_ERROR &&
	         error->code == GEDIT_DOCUMENT_ERROR_CONVERSION_FALLBACK)
	{
		error_message = g_strdup_printf (_("There was a problem opening the file %s."),
						 uri_for_display);
		message_details = g_strconcat (_("The file you opened has some invalid characters. "
					       "If you continue editing this file you could make this "
					       "document useless."), "\n",
					       _("You can also choose another character encoding and try again."),
					       NULL);
		edit_anyway = TRUE;
		convert_error = TRUE;
	}
	else if (is_gio_error (error, G_IO_ERROR_INVALID_DATA) && encoding != NULL)
	{
		error_message = g_strdup_printf (_("Could not open the file %s using the %s character encoding."),
						 uri_for_display, 
						 encoding_name);
		message_details = g_strconcat (_("Please check that you are not trying to open a binary file."), "\n",
					       _("Select a different character encoding from the menu and try again."), NULL);
		convert_error = TRUE;
	}
	else
	{
		parse_error (error, &error_message, &message_details, uri, uri_for_display);
	}

	if (error_message == NULL)
	{
		error_message = g_strdup_printf (_("Could not open the file %s."),
						 uri_for_display);
	}

	if (convert_error)
	{
		message_area = create_conversion_error_message_area (error_message,
								     message_details,
								     edit_anyway);
	}
	else
	{
		message_area = create_io_loading_error_message_area (error_message,
								     message_details,
								     is_recoverable_error (error));
	}

	g_free (uri_for_display);
	g_free (encoding_name);
	g_free (error_message);
	g_free (message_details);
	
	return message_area;
}
GtkWidget *
gedit_file_already_open_warning_message_area_new (const gchar *uri)
{
	GtkWidget *message_area;
	GtkWidget *hbox_content;
	GtkWidget *image;
	GtkWidget *vbox;
	gchar *primary_markup;
	gchar *secondary_markup;
	GtkWidget *primary_label;
	GtkWidget *secondary_label;
	gchar *primary_text;
	const gchar *secondary_text;
	gchar *full_formatted_uri;
	gchar *uri_for_display;
	gchar *temp_uri_for_display;
	
	full_formatted_uri = gedit_utils_uri_for_display (uri);

	/* Truncate the URI so it doesn't get insanely wide. Note that even
	 * though the dialog uses wrapped text, if the URI doesn't contain
	 * white space then the text-wrapping code is too stupid to wrap it.
	 */
	temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri, 
								MAX_URI_IN_DIALOG_LENGTH);								
	g_free (full_formatted_uri);
	
	uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
	g_free (temp_uri_for_display);

#if !GTK_CHECK_VERSION (2, 17, 1)
	message_area = gedit_message_area_new ();
	gedit_message_area_add_button (GEDIT_MESSAGE_AREA (message_area),
				       _("Edit Any_way"),
				       GTK_RESPONSE_YES);
	gedit_message_area_add_button (GEDIT_MESSAGE_AREA (message_area),
				       _("D_on't Edit"),
				       GTK_RESPONSE_CANCEL);
#else
	message_area = gtk_info_bar_new ();
	gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
	/* Translators: the access key chosen for this string should be
	 different from other main menu access keys (Open, Edit, View...) */
				 _("Edit Any_way"),
				 GTK_RESPONSE_YES);
	gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
	/* Translators: the access key chosen for this string should be
	 different from other main menu access keys (Open, Edit, View...) */
				 _("D_on't Edit"),
				 GTK_RESPONSE_CANCEL);
	gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area),
				       GTK_MESSAGE_WARNING);
#endif

	hbox_content = gtk_hbox_new (FALSE, 8);

	image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG);
	gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);

	vbox = gtk_vbox_new (FALSE, 6);
	gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);

	primary_text = g_strdup_printf (_("This file (%s) is already open in another gedit window."), uri_for_display);
	g_free (uri_for_display);
	
	primary_markup = g_strdup_printf ("<b>%s</b>", primary_text);
	g_free (primary_text);
	primary_label = gtk_label_new (primary_markup);
	g_free (primary_markup);
	gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
	gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
	gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
	gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5);
	GTK_WIDGET_SET_FLAGS (primary_label, GTK_CAN_FOCUS);
	gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);

	secondary_text = _("gedit opened this instance of the file in a non-editable way. "
			   "Do you want to edit it anyway?");
	secondary_markup = g_strdup_printf ("<small>%s</small>",
					    secondary_text);
	secondary_label = gtk_label_new (secondary_markup);
	g_free (secondary_markup);
	gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
	GTK_WIDGET_SET_FLAGS (secondary_label, GTK_CAN_FOCUS);
	gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
	gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
	gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
	gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);

	gtk_widget_show_all (hbox_content);
	set_contents (message_area, hbox_content);

	return message_area;
}
GtkWidget *
gedit_externally_modified_message_area_new (const gchar *uri,
					    gboolean     document_modified)
{
	gchar *full_formatted_uri;
	gchar *uri_for_display;
	gchar *temp_uri_for_display;
	const gchar *primary_text;
	const gchar *secondary_text;
	GtkWidget *message_area;

	g_return_val_if_fail (uri != NULL, NULL);

	full_formatted_uri = gedit_utils_uri_for_display (uri);

	/* Truncate the URI so it doesn't get insanely wide. Note that even
	 * though the dialog uses wrapped text, if the URI doesn't contain
	 * white space then the text-wrapping code is too stupid to wrap it.
	 */
	temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri, 
								MAX_URI_IN_DIALOG_LENGTH);
	g_free (full_formatted_uri);

	uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
	g_free (temp_uri_for_display);

	// FIXME: review this message, it's not clear since for the user the "modification"
	// could be interpreted as the changes he made in the document. beside "reading" is
	// not accurate (since last load/save)
	primary_text = g_strdup_printf (_("The file %s changed on disk."),
					uri_for_display);
	g_free (uri_for_display);

	if (document_modified)
		secondary_text = _("Do you want to drop your changes and reload the file?");
	else
		secondary_text = _("Do you want to reload the file?");

#if !GTK_CHECK_VERSION (2, 17, 1)
	message_area = gedit_message_area_new ();
	
	gedit_message_area_add_stock_button_with_text (GEDIT_MESSAGE_AREA (message_area),
						       _("_Reload"),
						       GTK_STOCK_REFRESH,
						       GTK_RESPONSE_OK);

	gedit_message_area_add_button (GEDIT_MESSAGE_AREA (message_area),
				       GTK_STOCK_CANCEL,
				       GTK_RESPONSE_CANCEL);
#else
	message_area = gtk_info_bar_new ();
	
	info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area),
					     _("_Reload"),
					     GTK_STOCK_REFRESH,
					     GTK_RESPONSE_OK);
	gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
				 GTK_STOCK_CANCEL,
				 GTK_RESPONSE_CANCEL);
	gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area),
				       GTK_MESSAGE_WARNING);
#endif

	set_message_area_text_and_icon (message_area,
					"gtk-dialog-warning",
					primary_text,
					secondary_text);

	return message_area;
}
static gboolean
parse_gio_error (gint          code,
	         gchar       **error_message, 
	         gchar       **message_details, 
	         const gchar  *uri, 
	         const gchar  *uri_for_display)
{
	gboolean ret = TRUE;

	switch (code)
	{
	case G_IO_ERROR_NOT_FOUND:
	case G_IO_ERROR_NOT_DIRECTORY:
		*error_message = g_strdup_printf (_("Could not find the file %s."),
						  uri_for_display);
		*message_details = g_strdup (_("Please check that you typed the "
				      	       "location correctly and try again."));
		break;
	case G_IO_ERROR_NOT_SUPPORTED:
		{
			gchar *scheme_string;
			gchar *scheme_markup;
			
			scheme_string = g_uri_parse_scheme (uri);

			if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL))
			{
				scheme_markup = g_markup_printf_escaped ("<i>%s:</i>", scheme_string);

				/* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */
				*message_details = g_strdup_printf (_("gedit cannot handle %s locations."),
								   scheme_markup);
				g_free (scheme_markup);
			}
			else
			{
				*message_details = g_strdup (_("gedit cannot handle this location."));
			}	

			g_free (scheme_string);
		}
		break;

	case G_IO_ERROR_NOT_MOUNTABLE_FILE:
		*message_details = g_strdup (_("The location of the file cannot be mounted."));
		break;
	
	case G_IO_ERROR_NOT_MOUNTED:
		*message_details = g_strdup( _("The location of the file cannot be accessed because it is not mounted."));

		break;	
	case G_IO_ERROR_IS_DIRECTORY:
		*error_message = g_strdup_printf (_("%s is a directory."),
						 uri_for_display);
		*message_details = g_strdup (_("Please check that you typed the "
					      "location correctly and try again."));
		break;
		
	case G_IO_ERROR_INVALID_FILENAME:
		*error_message = g_strdup_printf (_("%s is not a valid location."),
						 uri_for_display);
		*message_details = g_strdup (_("Please check that you typed the "
					      "location correctly and try again."));
		break;
		
	case G_IO_ERROR_HOST_NOT_FOUND:
		/* This case can be hit for user-typed strings like "foo" due to
		 * the code that guesses web addresses when there's no initial "/".
		 * But this case is also hit for legitimate web addresses when
		 * the proxy is set up wrong.
		 */
		{
			gchar *hn = NULL;

			if (gedit_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL))
			{
				if (hn != NULL)
				{
					gchar *host_markup;
					gchar *host_name;

					host_name = gedit_utils_make_valid_utf8 (hn);
					g_free (hn);

					host_markup = g_markup_printf_escaped ("<i>%s</i>", host_name);
					g_free (host_name);

					/* Translators: %s is a host name */
					*message_details = g_strdup_printf (
						_("Host %s could not be found. "
						"Please check that your proxy settings "
						"are correct and try again."),
						host_markup);

					g_free (host_markup);
				}
			}
			
			if (!*message_details)
			{
				/* use the same string as INVALID_HOST */
				*message_details = g_strdup_printf (
					_("Hostname was invalid. "
					  "Please check that you typed the location "
					  "correctly and try again."));
			}
		}
		break;

	case G_IO_ERROR_NOT_REGULAR_FILE:
		*message_details = g_strdup_printf (_("%s is not a regular file."),
						   uri_for_display);
		break;

	case G_IO_ERROR_TIMED_OUT:
		*message_details = g_strdup (_("Connection timed out. Please try again."));
		break;

	default:
		ret = FALSE;
		break;
	}

	return ret;
}
GtkWidget *
gedit_unrecoverable_saving_error_message_area_new (const gchar  *uri,
						   const GError *error)
{
	gchar *error_message = NULL;
	gchar *message_details = NULL;
	gchar *full_formatted_uri;
	gchar *scheme_string;
	gchar *scheme_markup;
	gchar *uri_for_display;
	gchar *temp_uri_for_display;
	GtkWidget *message_area;

	g_return_val_if_fail (uri != NULL, NULL);
	g_return_val_if_fail (error != NULL, NULL);
	g_return_val_if_fail ((error->domain == GEDIT_DOCUMENT_ERROR) || 
			      (error->domain == G_IO_ERROR), NULL);

	full_formatted_uri = gedit_utils_uri_for_display (uri);

	/* Truncate the URI so it doesn't get insanely wide. Note that even
	 * though the dialog uses wrapped text, if the URI doesn't contain
	 * white space then the text-wrapping code is too stupid to wrap it.
	 */
	temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri, 
								MAX_URI_IN_DIALOG_LENGTH);
	g_free (full_formatted_uri);

	uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
	g_free (temp_uri_for_display);

	if (is_gio_error (error, G_IO_ERROR_NOT_SUPPORTED))
	{
		scheme_string = g_uri_parse_scheme (uri);

		if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL))
		{
			scheme_markup = g_markup_printf_escaped ("<i>%s:</i>", scheme_string);

			/* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */
			message_details = g_strdup_printf (_("gedit cannot handle %s locations in write mode. "
							     "Please check that you typed the "
							     "location correctly and try again."),
							   scheme_markup);
			g_free (scheme_markup);
		}
		else
		{
			message_details = g_strdup (_("gedit cannot handle this location in write mode. "
						      "Please check that you typed the "
						      "location correctly and try again."));
		}

		g_free (scheme_string);
	}
	else if (is_gio_error (error, G_IO_ERROR_INVALID_FILENAME))
	{
		message_details = g_strdup (_("%s is not a valid location. " 
					      "Please check that you typed the "
					      "location correctly and try again."));
	}
	else if (is_gio_error (error, G_IO_ERROR_PERMISSION_DENIED))
	{
		message_details = g_strdup (_("You do not have the permissions necessary to save the file. "
					      "Please check that you typed the "
					      "location correctly and try again."));
	}
	else if (is_gio_error (error, G_IO_ERROR_NO_SPACE))
	{
		message_details = g_strdup (_("There is not enough disk space to save the file. "
					      "Please free some disk space and try again."));
	}
	else if (is_gio_error (error, G_IO_ERROR_READ_ONLY))
	{
		message_details = g_strdup (_("You are trying to save the file on a read-only disk. "
					      "Please check that you typed the location "
					      "correctly and try again."));
	}
	else if (is_gio_error (error, G_IO_ERROR_EXISTS))
	{
		message_details = g_strdup (_("A file with the same name already exists. "
					      "Please use a different name."));
	}
	else if (is_gio_error (error, G_IO_ERROR_FILENAME_TOO_LONG))
	{
		message_details = g_strdup (_("The disk where you are trying to save the file has "
					      "a limitation on length of the file names. "
					      "Please use a shorter name."));
	}
	else if (error->domain == GEDIT_DOCUMENT_ERROR &&
		 error->code == GEDIT_DOCUMENT_ERROR_TOO_BIG)
	{
		message_details = g_strdup (_("The disk where you are trying to save the file has "
					      "a limitation on file sizes. Please try saving "
					      "a smaller file or saving it to a disk that does not "
					      "have this limitation."));
	}
	else
	{
		parse_error (error, 
			     &error_message, 
			     &message_details, 
			     uri, 
			     uri_for_display);
	}

	if (error_message == NULL)
	{
		error_message = g_strdup_printf (_("Could not save the file %s."),
						 uri_for_display);
	}

	message_area = create_io_loading_error_message_area (error_message,
							     message_details,
							     FALSE);

	g_free (uri_for_display);
	g_free (error_message);
	g_free (message_details);

	return message_area;
}
Exemple #13
0
/* TODO: just add a translation_doamin arg to get_ui_objects method */
static gboolean
get_ui_objects_with_translation_domain (const gchar  *filename,
                                        const gchar  *translation_domain,
                                        gchar       **root_objects,
                                        GtkWidget   **error_widget,
                                        const gchar  *object_name,
                                        va_list       args)
{
	GtkBuilder *builder;
	const gchar *name;
	GError *error = NULL;
	gchar *filename_markup;
	gboolean ret = TRUE;

	g_return_val_if_fail (filename != NULL, FALSE);
	g_return_val_if_fail (error_widget != NULL, FALSE);
	g_return_val_if_fail (object_name != NULL, FALSE);

	filename_markup = g_markup_printf_escaped ("<i>%s</i>", filename);
	*error_widget = NULL;

	builder = gtk_builder_new ();

	if (translation_domain != NULL)
	{
		gtk_builder_set_translation_domain (builder, translation_domain);
	}

	if (root_objects != NULL)
	{
		gtk_builder_add_objects_from_file (builder,
						   filename,
						   root_objects,
						   &error);
	}
	else
	{
		gtk_builder_add_from_file (builder,
					   filename,
					   &error);
	}

	if (error != NULL)
	{
		*error_widget = handle_builder_error (_("Unable to open UI file %s. Error: %s"),
						      filename_markup,
						      error->message);
		g_error_free (error);
		g_free (filename_markup);
		g_object_unref (builder);

		return FALSE;
	}

	for (name = object_name; name; name = va_arg (args, const gchar *))
	{
		GObject **gobj;

		gobj = va_arg (args, GObject **);
		*gobj = gtk_builder_get_object (builder, name);

		if (!*gobj)
		{
			*error_widget = handle_builder_error (_("Unable to find the object '%s' inside file %s."),
							      name,
							      filename_markup),
			ret = FALSE;
			break;
		}

		/* we return a new ref for the root objects,
		 * the others are already reffed by their parent root object */
		if (root_objects != NULL)
		{
			gint i;

			for (i = 0; root_objects[i] != NULL; ++i)
			{
				if ((strcmp (name, root_objects[i]) == 0))
				{
					g_object_ref (*gobj);
				}
			}
		}
	}

	g_free (filename_markup);
	g_object_unref (builder);

	return ret;
}
Exemple #14
0
static GtkWidget *create_history_menu(GtkWidget *history_menu) {
	GtkWidget *menu_item, *item_label;
	history_menu = gtk_menu_new();
	g_signal_connect((GObject*)history_menu, "key-press-event", (GCallback)menu_key_pressed, NULL);

	/* Items */
	if ((history != NULL) && (history->data != NULL))
	{
		/* Declare some variables */
		GList* element;
		gint element_number = 0;
		gint element_number_small = 0;
		gchar* primary_temp = gtk_clipboard_wait_for_text(primary);
		gchar* clipboard_temp = gtk_clipboard_wait_for_text(clipboard);
		/* Reverse history if enabled */
		if (prefs.reverse_history)
		{
			history = g_list_reverse(history);
			element_number = g_list_length(history) - 1;
		}
		/* Go through each element and adding each */
		for (element = history; (element != NULL) && (element_number_small < prefs.items_menu); element = element->next)
		{
			history_item *elem_data = element->data;
			GString* string = g_string_new((gchar*)elem_data->content);
			/* Ellipsize text */
			string = ellipsize_string(string);
			/* Remove control characters */
			string = remove_newlines_string(string);
			/* Make new item with ellipsized text */
			gchar* list_item;
			if (prefs.show_indexes)
			{
				list_item = g_strdup_printf("%d. %s", (element_number_small+1), string->str);
			} else {
				list_item = g_strdup(string->str);
			}
			menu_item = gtk_menu_item_new_with_label(list_item);
			g_signal_connect((GObject*)menu_item, "activate", (GCallback)item_selected, GINT_TO_POINTER(element_number));

			/* Modify menu item label properties */
			item_label = gtk_bin_get_child((GtkBin*)menu_item);
			gtk_label_set_single_line_mode((GtkLabel*)item_label, prefs.single_line);

			/* Check if item is also clipboard text and make bold */
			if ((clipboard_temp) && (g_strcmp0((gchar*)elem_data->content, clipboard_temp) == 0))
			{
				gchar* bold_text = g_markup_printf_escaped("<b>%s</b>", list_item);
				gtk_label_set_markup((GtkLabel*)item_label, bold_text);
				g_free(bold_text);
			}
			else if ((primary_temp) && (g_strcmp0((gchar*)elem_data->content, primary_temp) == 0))
			{
				gchar* italic_text = g_markup_printf_escaped("<i>%s</i>", list_item);
				gtk_label_set_markup((GtkLabel*)item_label, italic_text);
				g_free(italic_text);
			}
			g_free(list_item);
			/* Append item */
			gtk_menu_shell_append((GtkMenuShell*)history_menu, menu_item);
			/* Prepare for next item */
			g_string_free(string, TRUE);
			if (prefs.reverse_history)
				element_number--;
			else
				element_number++;
				element_number_small++;
		}
		/* Cleanup */
		g_free(primary_temp);
		g_free(clipboard_temp);
		/* Return history to normal if reversed */
		if (prefs.reverse_history)
			history = g_list_reverse(history);
	}
	else
	{
		/* Nothing in history so adding empty */
		menu_item = gtk_menu_item_new_with_label(_("Empty"));
		gtk_widget_set_sensitive(menu_item, FALSE);
		gtk_menu_shell_append((GtkMenuShell*)history_menu, menu_item);
	}
	if (prefs.statics_show) {
		/* -------------------- */
		gtk_menu_shell_append((GtkMenuShell*)history_menu, gtk_separator_menu_item_new());

		/* Items */
		GList *elem = history;
		int elem_num = 0;
		int elem_num_static = 1;
		while (elem && (elem_num_static <= prefs.statics_items)) {
			history_item *hitem = elem->data;
			if (hitem->is_static) {
				GString* string = g_string_new((gchar*)hitem->content);
				/* Ellipsize text */
				string = ellipsize_string(string);
				/* Remove control characters */
				string = remove_newlines_string(string);
				gchar* list_item;
				if (prefs.show_indexes)
				{
					list_item = g_strdup_printf("%d. %s", (elem_num_static), string->str);
				} else {
					list_item = g_strdup(string->str);
				}
				menu_item = gtk_menu_item_new_with_label(list_item);
				g_signal_connect((GObject*)menu_item, "activate", (GCallback)item_selected, GINT_TO_POINTER(elem_num));
				/* Modify menu item label properties */
				item_label = gtk_bin_get_child((GtkBin*)menu_item);
				gtk_label_set_single_line_mode((GtkLabel*)item_label, prefs.single_line);
				g_free(list_item);
				g_string_free(string, TRUE);
				gtk_menu_shell_append((GtkMenuShell*)history_menu, menu_item);
				elem_num_static++;
			}
			elem_num++;
			elem = elem->next;
		}
	}
	/* Show a notice in offline mode */
	if (prefs.offline_mode) {
		gtk_menu_shell_append((GtkMenuShell*)history_menu, gtk_separator_menu_item_new());

		menu_item = gtk_menu_item_new_with_label("");
		item_label = gtk_bin_get_child((GtkBin*)menu_item);
		gtk_label_set_markup((GtkLabel*)item_label, "<b>Offline mode is ON</b>");
		gtk_label_set_single_line_mode((GtkLabel*)item_label, TRUE);
		gtk_widget_set_sensitive(item_label, FALSE);
		gtk_menu_shell_append((GtkMenuShell*)history_menu, menu_item);
	}
	return history_menu;
}
static gboolean
trash_empty_update_dialog (gpointer user_data)
{
        gsize deleted, total;
        GFile *file;
        gboolean actually_deleting;

        g_assert (trash_empty_update_pending);

        deleted = trash_empty_deleted_files;
        total = trash_empty_total_files;
        file = trash_empty_current_file;
        actually_deleting = trash_empty_actually_deleting;

        /* maybe the done() got processed first. */
        if (!trash_empty_dialog)
                goto out;

        if (!actually_deleting) {
                /* If we havent finished counting yet, then pulse the progressbar every 100ms.
                 * This stops the user from thinking the dialog has frozen if there are
                 * a lot of files to delete. We don't pulse it every time we are called from the
                 * worker thread, otherwise it moves to fast and looks hideous
                 */
                if (timer) {
                        if (g_timer_elapsed (timer, NULL) > 0.1) {
                                gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progressbar));
                                g_timer_start (timer);
                        }
                } else {
                        timer = g_timer_new ();
                        g_timer_start (timer);
                        gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progressbar));
                }
        } else {
                gchar *text;
                gchar *tmp;
                gchar *markup;
                GFile *parent;

                text = g_strdup_printf (_("Removing item %lu of %lu"),
                                        deleted, total);
                gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar), text);

                g_free (text);

                if (deleted > total)
                        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progressbar), 1.0);
                else
                        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progressbar),
                                                       (gdouble) deleted / (gdouble) total);

                parent = g_file_get_parent (file);
                text = g_file_get_uri (parent);
                g_object_unref (parent);

                gtk_label_set_text (GTK_LABEL (location_label), text);
                g_free (text);

                tmp = g_file_get_basename (file);
                text = g_markup_printf_escaped (_("Removing: %s"), tmp);
                markup = g_strdup_printf ("<i>%s</i>", text);
                gtk_label_set_markup (GTK_LABEL (file_label), text);
                g_free (markup);
                g_free (text);
                g_free (tmp);

                /* unhide the labels */
                gtk_widget_show_all (GTK_WIDGET (trash_empty_dialog));
        }

out:
        trash_empty_current_file = NULL;
        g_object_unref (file);

        trash_empty_update_pending = FALSE;

        return FALSE;
}
GtkWidget *
gedit_externally_modified_saving_error_message_area_new (
						const gchar  *uri,
						const GError *error)
{
	GtkWidget *message_area;
	GtkWidget *hbox_content;
	GtkWidget *image;
	GtkWidget *vbox;
	gchar *primary_markup;
	gchar *secondary_markup;
	GtkWidget *primary_label;
	GtkWidget *secondary_label;
	gchar *primary_text;
	const gchar *secondary_text;
	gchar *full_formatted_uri;
	gchar *uri_for_display;
	gchar *temp_uri_for_display;

	g_return_val_if_fail (uri != NULL, NULL);
	g_return_val_if_fail (error != NULL, NULL);
	g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
	g_return_val_if_fail (error->code == GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, NULL);

	full_formatted_uri = gedit_utils_uri_for_display (uri);

	/* Truncate the URI so it doesn't get insanely wide. Note that even
	 * though the dialog uses wrapped text, if the URI doesn't contain
	 * white space then the text-wrapping code is too stupid to wrap it.
	 */
	temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri, 
								MAX_URI_IN_DIALOG_LENGTH);								
	g_free (full_formatted_uri);

	uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
	g_free (temp_uri_for_display);

#if !GTK_CHECK_VERSION (2, 17, 1)
	message_area = gedit_message_area_new ();
	gedit_message_area_add_stock_button_with_text (GEDIT_MESSAGE_AREA (message_area),
						       _("S_ave Anyway"),
						       GTK_STOCK_SAVE,
						       GTK_RESPONSE_YES);
	gedit_message_area_add_button (GEDIT_MESSAGE_AREA (message_area),
				       _("D_on't Save"),
				       GTK_RESPONSE_CANCEL);
#else
	message_area = gtk_info_bar_new ();
	
	info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area),
					     _("S_ave Anyway"),
					     GTK_STOCK_SAVE,
					     GTK_RESPONSE_YES);
	gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
				 _("D_on't Save"),
				 GTK_RESPONSE_CANCEL);
	gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area),
				       GTK_MESSAGE_WARNING);
#endif

	hbox_content = gtk_hbox_new (FALSE, 8);

	image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG);
	gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);

	vbox = gtk_vbox_new (FALSE, 6);
	gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);

	// FIXME: review this message, it's not clear since for the user the "modification"
	// could be interpreted as the changes he made in the document. beside "reading" is
	// not accurate (since last load/save)
	primary_text = g_strdup_printf (_("The file %s has been modified since reading it."),
					uri_for_display);
	g_free (uri_for_display);

	primary_markup = g_strdup_printf ("<b>%s</b>", primary_text);
	g_free (primary_text);
	primary_label = gtk_label_new (primary_markup);
	g_free (primary_markup);
	gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
	gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
	gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
	gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5);
	GTK_WIDGET_SET_FLAGS (primary_label, GTK_CAN_FOCUS);
	gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);

	secondary_text = _("If you save it, all the external changes could be lost. Save it anyway?");
	secondary_markup = g_strdup_printf ("<small>%s</small>",
					    secondary_text);
	secondary_label = gtk_label_new (secondary_markup);
	g_free (secondary_markup);
	gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
	GTK_WIDGET_SET_FLAGS (secondary_label, GTK_CAN_FOCUS);
	gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
	gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
	gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
	gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);

	gtk_widget_show_all (hbox_content);
	set_contents (message_area, hbox_content);

	return message_area;
}
/** \brief Show satellite popup menu.
 *  \param sat Pointer to the satellite data.
 *  \param qth The current location.
 *  \param pview The GtkPolarView widget.
 *  \param event The mouse-click related event info
 *  \param toplevel The toplevel window or NULL.
 *
 */
void
gtk_polar_view_popup_exec(sat_t * sat,
                          qth_t * qth,
                          GtkPolarView * pview,
                          GdkEventButton * event, GtkWidget * toplevel)
{
    GtkWidget      *menu;
    GtkWidget      *menuitem;
    GtkWidget      *label;
    GtkWidget      *image;
    gchar          *buff;
    sat_obj_t      *obj = NULL;
    gint           *catnum;



    menu = gtk_menu_new();

    /* first menu item is the satellite name, centered */
    menuitem = gtk_image_menu_item_new();
    label = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
    buff = g_markup_printf_escaped("<b>%s</b>", sat->nickname);
    gtk_label_set_markup(GTK_LABEL(label), buff);
    g_free(buff);
    gtk_container_add(GTK_CONTAINER(menuitem), label);
    image = gtk_image_new_from_stock(GTK_STOCK_INFO, GTK_ICON_SIZE_MENU);
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);

    /* attach data to menuitem and connect callback */
    g_object_set_data(G_OBJECT(menuitem), "sat", sat);
    g_object_set_data(G_OBJECT(menuitem), "qth", qth);
    g_signal_connect(menuitem, "activate", G_CALLBACK(show_sat_info_menu_cb),
                     toplevel);

    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);

    /* separator */
    menuitem = gtk_separator_menu_item_new();
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);

    /* add the menu items for current,next, and future passes. */
    add_pass_menu_items(menu, sat, qth, &pview->tstamp, GTK_WIDGET(pview));

    /* separator */
    menuitem = gtk_separator_menu_item_new();
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);

    /* get sat obj since we'll need it for the remaining items */
    catnum = g_new0(gint, 1);
    *catnum = sat->tle.catnr;
    obj = SAT_OBJ(g_hash_table_lookup(pview->obj, catnum));
    g_free(catnum);

    /* show track */
    menuitem = gtk_check_menu_item_new_with_label(_("Sky track"));
    g_object_set_data(G_OBJECT(menuitem), "sat", sat);
    g_object_set_data(G_OBJECT(menuitem), "qth", qth);
    g_object_set_data(G_OBJECT(menuitem), "obj", obj);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
                                   obj->showtrack);
    g_signal_connect(menuitem, "activate", G_CALLBACK(track_toggled), pview);

    /* disable menu item if satellite is geostationary */
    if (sat->otype == ORBIT_TYPE_GEO)
        gtk_widget_set_sensitive(menuitem, FALSE);

    /* target */
    /*      menuitem = gtk_check_menu_item_new_with_label (_("Set as target")); */
    /*      g_object_set_data (G_OBJECT (menuitem), "sat", sat); */
    /*      g_object_set_data (G_OBJECT (menuitem), "qth", qth); */
    /*      g_object_set_data (G_OBJECT (menuitem), "obj", obj); */
    /*      gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); */
    /*      gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), obj->istarget); */
    /*      g_signal_connect (menuitem, "activate", G_CALLBACK (target_toggled), pview); */

    gtk_widget_show_all(menu);

    /* Note: event can be NULL here when called from view_onPopupMenu;
     *  gdk_event_get_time() accepts a NULL argument */
    gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
                   (event != NULL) ? event->button : 0,
                   gdk_event_get_time((GdkEvent *) event));


}
GtkWidget *
gedit_no_backup_saving_error_message_area_new (const gchar  *uri,
					       const GError *error)
{
	GtkWidget *message_area;
	GtkWidget *hbox_content;
	GtkWidget *image;
	GtkWidget *vbox;
	gchar *primary_markup;
	gchar *secondary_markup;
	GtkWidget *primary_label;
	GtkWidget *secondary_label;
	gchar *primary_text;
	const gchar *secondary_text;
	gchar *full_formatted_uri;
	gchar *uri_for_display;
	gchar *temp_uri_for_display;

	g_return_val_if_fail (uri != NULL, NULL);
	g_return_val_if_fail (error != NULL, NULL);
	g_return_val_if_fail (((error->domain == GEDIT_DOCUMENT_ERROR &&
			        error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP) ||
			       (error->domain == G_IO_ERROR &&
			        error->code == G_IO_ERROR_CANT_CREATE_BACKUP)), NULL);

	full_formatted_uri = gedit_utils_uri_for_display (uri);

	/* Truncate the URI so it doesn't get insanely wide. Note that even
	 * though the dialog uses wrapped text, if the URI doesn't contain
	 * white space then the text-wrapping code is too stupid to wrap it.
	 */
	temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri, 
								MAX_URI_IN_DIALOG_LENGTH);								
	g_free (full_formatted_uri);

	uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
	g_free (temp_uri_for_display);

#if !GTK_CHECK_VERSION (2, 17, 1)
	message_area = gedit_message_area_new ();
	gedit_message_area_add_stock_button_with_text (GEDIT_MESSAGE_AREA (message_area),
						       _("S_ave Anyway"),
						       GTK_STOCK_SAVE,
						       GTK_RESPONSE_YES);
	gedit_message_area_add_button (GEDIT_MESSAGE_AREA (message_area),
				       _("D_on't Save"),
				       GTK_RESPONSE_CANCEL);
#else
	message_area = gtk_info_bar_new ();
	
	info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area),
					     _("S_ave Anyway"),
					     GTK_STOCK_SAVE,
					     GTK_RESPONSE_YES);
	gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
				 _("D_on't Save"),
				 GTK_RESPONSE_CANCEL);
	gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area),
				       GTK_MESSAGE_WARNING);
#endif

	hbox_content = gtk_hbox_new (FALSE, 8);

	image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG);
	gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);

	vbox = gtk_vbox_new (FALSE, 6);
	gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);

	// FIXME: review this messages

	if (gedit_prefs_manager_get_create_backup_copy ())
		primary_text = g_strdup_printf (_("Could not create a backup file while saving %s"),
						uri_for_display);
	else
		primary_text = g_strdup_printf (_("Could not create a temporary backup file while saving %s"),
						uri_for_display);

	g_free (uri_for_display);

	primary_markup = g_strdup_printf ("<b>%s</b>", primary_text);
	g_free (primary_text);
	primary_label = gtk_label_new (primary_markup);
	g_free (primary_markup);
	gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
	gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
	gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
	gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5);
	GTK_WIDGET_SET_FLAGS (primary_label, GTK_CAN_FOCUS);
	gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);

	secondary_text = _("gedit could not back up the old copy of the file before saving the new one. "
			   "You can ignore this warning and save the file anyway, but if an error "
			   "occurs while saving, you could lose the old copy of the file. Save anyway?");
	secondary_markup = g_strdup_printf ("<small>%s</small>",
					    secondary_text);
	secondary_label = gtk_label_new (secondary_markup);
	g_free (secondary_markup);
	gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
	GTK_WIDGET_SET_FLAGS (secondary_label, GTK_CAN_FOCUS);
	gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
	gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
	gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
	gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);

	gtk_widget_show_all (hbox_content);
	set_contents (message_area, hbox_content);

	return message_area;
}
Exemple #19
0
/**
 * gdaui_dsn_editor_set_dsn
 * @editor: a #GdauiDsnEditor widget
 * @dsn_info: (allow-none): a #GdaDsnInfo pointer or %NULL
 *
 *
 * Requests that @editor update its contents with @dsn_info's contents
 */
void
gdaui_dsn_editor_set_dsn (GdauiDsnEditor *editor, const GdaDsnInfo *dsn_info)
{
	g_return_if_fail (GDAUI_IS_DSN_EDITOR (editor));
	editor->priv->no_change_signal = TRUE;

	if (dsn_info) {
		GdaProviderInfo *pinfo;
		pinfo = gda_config_get_provider_info (dsn_info->provider);

		GdkPixbuf *pix;
		pix = support_create_pixbuf_for_provider (pinfo);
		if (pix) {
			gtk_image_set_from_pixbuf (GTK_IMAGE (editor->priv->icon), pix);
			g_object_unref (pix);
		}
		else
			gtk_image_clear (GTK_IMAGE (editor->priv->icon));

		if (pinfo)
			gtk_widget_hide (editor->priv->warning);
		else
			gtk_widget_show (editor->priv->warning);

		gchar *tmp;
		tmp = g_markup_printf_escaped ("<big><b>%s</b></big>", dsn_info->name);
		gtk_label_set_markup (GTK_LABEL (editor->priv->wname), tmp);
		g_free (tmp);

		g_free (editor->priv->name);
		editor->priv->name = g_strdup (dsn_info->name);
		gdaui_provider_selector_set_provider (GDAUI_PROVIDER_SELECTOR (editor->priv->wprovider), 
						      dsn_info->provider);
		_gdaui_provider_spec_editor_set_provider (GDAUI_PROVIDER_SPEC_EDITOR (editor->priv->dsn_spec),
							 dsn_info->provider);
		_gdaui_provider_spec_editor_set_specs (GDAUI_PROVIDER_SPEC_EDITOR (editor->priv->dsn_spec),
						      dsn_info->cnc_string);
		gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->wdesc)),
					  dsn_info->description ? dsn_info->description : "", -1);
		_gdaui_provider_auth_editor_set_provider (GDAUI_PROVIDER_AUTH_EDITOR (editor->priv->dsn_auth),
							 dsn_info->provider);
		_gdaui_provider_auth_editor_set_auth (GDAUI_PROVIDER_AUTH_EDITOR (editor->priv->dsn_auth),
						     dsn_info->auth_string);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->is_system), dsn_info->is_system);
		
		if (dsn_info->is_system && !gda_config_can_modify_system_config ()) {
			gtk_widget_set_sensitive (editor->priv->wprovider, FALSE);
			gtk_text_view_set_editable (GTK_TEXT_VIEW (editor->priv->wdesc), pinfo ? TRUE : FALSE);
			gtk_widget_set_sensitive (editor->priv->dsn_spec, FALSE);
			gtk_widget_set_sensitive (editor->priv->dsn_auth, FALSE);
			gtk_widget_set_sensitive (editor->priv->is_system, FALSE);
		}
		else {
			gtk_widget_set_sensitive (editor->priv->wprovider, pinfo ? TRUE : FALSE);
			gtk_text_view_set_editable (GTK_TEXT_VIEW (editor->priv->wdesc), pinfo ? TRUE : FALSE);
			gtk_widget_set_sensitive (editor->priv->dsn_spec, TRUE);
			gtk_widget_set_sensitive (editor->priv->dsn_auth, TRUE);
			gtk_widget_set_sensitive (editor->priv->is_system,
						  pinfo && gda_config_can_modify_system_config () ? TRUE : FALSE);
		}
	}
	else {
		gtk_image_clear (GTK_IMAGE (editor->priv->icon));
		gtk_label_set_text (GTK_LABEL (editor->priv->wname), "");
		gdaui_provider_selector_set_provider (GDAUI_PROVIDER_SELECTOR (editor->priv->wprovider), NULL);
		_gdaui_provider_spec_editor_set_provider (GDAUI_PROVIDER_SPEC_EDITOR (editor->priv->dsn_spec), NULL);
		gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->wdesc)), "", -1);
		_gdaui_provider_auth_editor_set_provider (GDAUI_PROVIDER_AUTH_EDITOR (editor->priv->dsn_auth), NULL);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->is_system), FALSE);

		gtk_widget_set_sensitive (editor->priv->wprovider, FALSE);
		gtk_text_view_set_editable (GTK_TEXT_VIEW (editor->priv->wdesc), FALSE);
		gtk_widget_set_sensitive (editor->priv->dsn_spec, FALSE);
		gtk_widget_set_sensitive (editor->priv->dsn_auth, FALSE);
		gtk_widget_set_sensitive (editor->priv->is_system, FALSE);
	}

	editor->priv->no_change_signal = FALSE;
	g_signal_emit (editor, gdaui_dsn_editor_signals[CHANGED], 0, NULL);
}
Exemple #20
0
static void
store_populate_menu_items (GtkListStore  *store,
                           GtkMenuShell  *menu,
                           const gchar   *parent_path)
{
  GList  *children;
  GList  *node;
  
  children = gtk_container_get_children (GTK_CONTAINER (menu));
  for (node = children; node; node = node->next) {
    if (GTK_IS_SEPARATOR_MENU_ITEM (node->data) ||
        ! gtk_widget_get_visible (node->data)) {
      /* skip that */
    } else if (GTK_IS_MENU_ITEM (node->data)) {
      GtkWidget    *submenu;
      gchar        *path;
      gchar        *item_label;
      gboolean      use_underline;
      GtkStockItem  item;
      
      if (GTK_IS_IMAGE_MENU_ITEM (node->data) &&
          gtk_image_menu_item_get_use_stock (node->data) &&
          gtk_stock_lookup (gtk_menu_item_get_label (node->data), &item)) {
        item_label = g_strdup (item.label);
        use_underline = TRUE;
      } else {
        item_label = g_strdup (gtk_menu_item_get_label (node->data));
        use_underline = gtk_menu_item_get_use_underline (node->data);
      }
      
      /* remove underlines */
      if (use_underline) {
        gchar  *p   = item_label;
        gsize   len = strlen (p);
        
        while ((p = strchr (p, '_')) != NULL) {
          len -= (gsize) (p - item_label);
          
          memmove (p, p + 1, len);
        }
      }
      
      if (parent_path) {
        path = g_strconcat (parent_path, PATH_SEPARATOR, item_label, NULL);
      } else {
        path = g_strdup (item_label);
      }
      
      submenu = gtk_menu_item_get_submenu (node->data);
      if (submenu) {
        /* go deeper in the menus... */
        store_populate_menu_items (store, GTK_MENU_SHELL (submenu), path);
      } else {
        gchar *tmp;
        gchar *tooltip;
        gchar *label = g_markup_printf_escaped ("<big>%s</big>", item_label);
        
        tooltip = gtk_widget_get_tooltip_markup (node->data);
        if (tooltip) {
          SETPTR (label, g_strconcat (label, "\n<small>", tooltip, "</small>", NULL));
          g_free (tooltip);
        }
        
        tmp = g_markup_escape_text (path, -1);
        SETPTR (label, g_strconcat (label, "\n<small><i>", tmp, "</i></small>", NULL));
        g_free (tmp);
        
        gtk_list_store_insert_with_values (store, NULL, -1,
                                           COL_LABEL, label,
                                           COL_PATH, path,
                                           COL_TYPE, COL_TYPE_MENU_ITEM,
                                           COL_WIDGET, node->data,
                                           -1);
        
        g_free (label);
      }
      
      g_free (item_label);
      g_free (path);
    } else {
      g_warning ("Unknown widget type in the menu: %s",
                 G_OBJECT_TYPE_NAME (node->data));
    }
  }
  g_list_free (children);
}
Exemple #21
0
static void
theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
				 EmpathyMessage    *msg)
{
	EmpathyChatTextView  *view = EMPATHY_CHAT_TEXT_VIEW (theme);
	EmpathyThemeBoxesPriv*priv = GET_PRIV (theme);
	EmpathyContact       *contact;
	EmpathyContact       *last_contact;
	GdkPixbuf            *avatar = NULL;
	GtkTextBuffer        *buffer;
	const gchar          *name;
	GtkTextIter           iter;
	GtkWidget            *label1, *label2;
	GtkTextChildAnchor   *anchor;
	GtkWidget            *box;
	gchar                *str;
	time_t                time_;
	gchar                *tmp;
	GtkTextIter           start;
	gboolean              color_set;
	GtkTextTagTable      *table;
	GtkTextTag           *tag;
	GString              *str_obj;

	contact = empathy_message_get_sender (msg);
	name = empathy_contact_get_name (contact);
	last_contact = empathy_chat_text_view_get_last_contact (view);
	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme));

	DEBUG ("Maybe add fancy header");

	/* Only insert a header if the previously inserted block is not the same
	 * as this one.
	 */
	if (empathy_contact_equal (last_contact, contact)) {
		return;
	}

	empathy_chat_text_view_append_spacing (view);

	/* Insert header line */
	gtk_text_buffer_get_end_iter (buffer, &iter);
	gtk_text_buffer_insert_with_tags_by_name (buffer,
						  &iter,
						  "\n",
						  -1,
						  EMPATHY_THEME_BOXES_TAG_HEADER_LINE,
						  NULL);

	gtk_text_buffer_get_end_iter (buffer, &iter);
	anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);

	/* Create a hbox for the header and resize it when the view allocation
	 * changes */
	box = gtk_hbox_new (FALSE, 0);
	g_signal_connect_object (view, "size-allocate",
				 G_CALLBACK (table_size_allocate_cb),
				 box, 0);

	/* Add avatar to the box if needed */
	if (priv->show_avatars) {
		avatar = theme_boxes_get_avatar_pixbuf_with_cache (contact);
		if (avatar) {
			GtkWidget *image;

			image = gtk_image_new_from_pixbuf (avatar);

			gtk_box_pack_start (GTK_BOX (box), image,
					    FALSE, TRUE, 2);
		}
	}

	/* Add contact alias */
	str = g_markup_printf_escaped ("<b>%s</b>", name);
	label1 = g_object_new (GTK_TYPE_LABEL,
			       "label", str,
			       "use-markup", TRUE,
			       "xalign", 0.0,
			       NULL);
	g_free (str);

	/* Add the message receive time */
	time_ = empathy_message_get_timestamp (msg);
	tmp = empathy_time_to_string_local (time_,
					   EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
	str = g_strdup_printf ("<i>%s</i>", tmp);
	label2 = g_object_new (GTK_TYPE_LABEL,
			       "label", str,
			       "use-markup", TRUE,
			       "xalign", 1.0,
			       NULL);

	str_obj = g_string_new ("\n- ");
	g_string_append (str_obj, name);
	g_string_append (str_obj, ", ");
	g_string_append (str_obj, tmp);
	g_string_append (str_obj, " -");
	g_free (tmp);
	g_free (str);

	/* Set foreground color of labels to the same color than the header tag. */
	table = gtk_text_buffer_get_tag_table (buffer);
	tag = gtk_text_tag_table_lookup (table, EMPATHY_THEME_BOXES_TAG_HEADER);
	g_object_get (tag, "foreground-set", &color_set, NULL);
	if (color_set) {
		GdkColor *color;

		g_object_get (tag, "foreground-gdk", &color, NULL);
		gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, color);
		gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, color);
		gdk_color_free (color);
	}

	/* Pack labels into the box */
	gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5);
	gtk_misc_set_alignment (GTK_MISC (label2), 1.0, 0.5);
	gtk_box_pack_start (GTK_BOX (box), label1, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (box), label2, TRUE, TRUE, 0);

	/* Add the header box to the text view */
	g_object_set_data_full (G_OBJECT (box),
				"str_obj",
				g_string_free (str_obj, FALSE),
				g_free);
	gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view),
					   box,
					   anchor);
	gtk_widget_show_all (box);

	/* Insert a header line */
	gtk_text_buffer_get_end_iter (buffer, &iter);
	start = iter;
	gtk_text_iter_backward_char (&start);
	gtk_text_buffer_apply_tag_by_name (buffer,
					   EMPATHY_THEME_BOXES_TAG_HEADER,
					   &start, &iter);
	gtk_text_buffer_insert_with_tags_by_name (buffer,
						  &iter,
						  "\n",
						  -1,
						  EMPATHY_THEME_BOXES_TAG_HEADER,
						  NULL);
	gtk_text_buffer_get_end_iter (buffer, &iter);
	gtk_text_buffer_insert_with_tags_by_name (buffer,
						  &iter,
						  "\n",
						  -1,
						  EMPATHY_THEME_BOXES_TAG_HEADER_LINE,
						  NULL);
}
Exemple #22
0
gint play_iter(GtkTreeIter * playiter, gint restart_second)
{

    gchar *subtitle = NULL;
    gchar *audiofile = NULL;
    GtkTreePath *path;
    gchar *uri = NULL;
    gint count;
    gint playlist;
    gchar *title = NULL;
    gchar *artist = NULL;
    gchar *album = NULL;
    gchar *audio_codec;
    gchar *video_codec = NULL;
    GtkAllocation alloc;
    gchar *demuxer = NULL;
    gboolean playable = TRUE;
    gint width;
    gint height;
    gfloat length_value;
    gint i;
    gpointer pixbuf;
    gchar *buffer = NULL;
    gchar *message = NULL;
    MetaData *metadata;
#ifdef GTK2_12_ENABLED
    GtkRecentData *recent_data;
#ifdef GIO_ENABLED
    GFile *file;
    GFileInfo *file_info;
#endif
#endif

    /*
       if (!(gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) == MEDIA_STATE_UNKNOWN ||
       gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) == MEDIA_STATE_QUIT)) {
       while (gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) != MEDIA_STATE_UNKNOWN) {
       gtk_main_iteration();
       }
       }
     */

    if (gtk_list_store_iter_is_valid(playliststore, playiter)) {
        gtk_tree_model_get(GTK_TREE_MODEL(playliststore), playiter, ITEM_COLUMN, &uri,
                           DESCRIPTION_COLUMN, &title, LENGTH_VALUE_COLUMN, &length_value,
                           ARTIST_COLUMN, &artist,
                           ALBUM_COLUMN, &album,
                           AUDIO_CODEC_COLUMN, &audio_codec,
                           VIDEO_CODEC_COLUMN, &video_codec,
                           VIDEO_WIDTH_COLUMN, &width,
                           VIDEO_HEIGHT_COLUMN, &height,
                           DEMUXER_COLUMN, &demuxer,
                           COVERART_COLUMN, &pixbuf,
                           SUBTITLE_COLUMN, &subtitle,
                           AUDIOFILE_COLUMN, &audiofile,
                           COUNT_COLUMN, &count, PLAYLIST_COLUMN, &playlist, PLAYABLE_COLUMN, &playable, -1);
        if (GTK_IS_TREE_SELECTION(selection)) {
            path = gtk_tree_model_get_path(GTK_TREE_MODEL(playliststore), playiter);
            if (path) {
                gtk_tree_selection_select_path(selection, path);
                if (GTK_IS_WIDGET(list))
                    gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(list), path, NULL, FALSE, 0, 0);
                buffer = gtk_tree_path_to_string(path);
                g_free(buffer);
                gtk_tree_path_free(path);
            }
        }
        gtk_list_store_set(playliststore, playiter, COUNT_COLUMN, count + 1, -1);
    } else {
        if (verbose > 1)
            printf("iter is invalid, nothing to play\n");
        return 0;
    }

    if (verbose) {
        printf("playing - %s\n", uri);
        printf("is playlist %i\n", playlist);
    }

    gmtk_get_allocation(GTK_WIDGET(media), &alloc);
    if (width == 0 || height == 0) {
        alloc.width = 16;
        alloc.height = 16;
    } else {
        alloc.width = width;
        alloc.height = height;
    }
    //printf("setting window size to %i x %i\n", alloc.width, alloc.height);
    gtk_widget_size_allocate(GTK_WIDGET(media), &alloc);
    while (gtk_events_pending())
        gtk_main_iteration();

    /*
       // wait for metadata to be available on this item
       if (!streaming_media(uri) && !device_name(uri)) {
       i = 0;
       if (playable) {
       while (demuxer == NULL && i < 50) {
       g_free(title);
       g_free(artist);
       g_free(album);
       g_free(audio_codec);
       g_free(video_codec);
       g_free(demuxer);
       g_free(subtitle);
       g_free(audiofile);
       if (gtk_list_store_iter_is_valid(playliststore, playiter)) {
       gtk_tree_model_get(GTK_TREE_MODEL(playliststore), playiter, LENGTH_VALUE_COLUMN,
       &length_value, DESCRIPTION_COLUMN, &title, ARTIST_COLUMN,
       &artist, ALBUM_COLUMN, &album, AUDIO_CODEC_COLUMN,
       &audio_codec, VIDEO_CODEC_COLUMN, &video_codec,
       VIDEO_WIDTH_COLUMN, &width, VIDEO_HEIGHT_COLUMN, &height,
       DEMUXER_COLUMN, &demuxer, COVERART_COLUMN, &pixbuf,
       SUBTITLE_COLUMN, &subtitle, AUDIOFILE_COLUMN, &audiofile,
       COUNT_COLUMN, &count, PLAYLIST_COLUMN, &playlist,
       PLAYABLE_COLUMN, &playable, -1);
       if (!playable) {
       if (verbose)
       printf("%s is not marked as playable (%i)\n", uri, i);
       play_next();
       return 0;
       }
       } else {
       if (verbose)
       printf("Current iter is not valid\n");
       return 1;   // error condition
       }
       gtk_main_iteration();
       i++;
       if (demuxer == NULL)
       g_usleep(10000);
       }
       } else {
       if (verbose)
       printf("%s is not marked as playable\n", uri);
       play_next();
       return 0;
       }

       }
     */
    // reset audio meter
    for (i = 0; i < METER_BARS; i++) {
        buckets[i] = 0;
        max_buckets[i] = 0;
    }

    gmtk_media_tracker_set_text(tracker, _("Playing"));
    gmtk_media_tracker_set_position(tracker, (gfloat) restart_second);
    gmtk_media_tracker_set_length(tracker, length_value);

    message = g_strdup_printf("<small>\n");
    if (title == NULL) {
        title = g_filename_display_basename(uri);
    }
    buffer = g_markup_printf_escaped("\t<big><b>%s</b></big>\n", title);
    message = g_strconcat(message, buffer, NULL);
    g_free(buffer);

    if (artist != NULL) {
        buffer = g_markup_printf_escaped("\t<i>%s</i>\n", artist);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    if (album != NULL) {
        buffer = g_markup_printf_escaped("\t%s\n", album);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    //buffer = g_markup_printf_escaped("\n\t%s\n", uri);
    //message = g_strconcat(message, buffer, NULL);
    //g_free(buffer);

    message = g_strconcat(message, "</small>", NULL);

    // probably not much cover art for random video files
    if (pixbuf == NULL && video_codec == NULL && !streaming_media(uri) && control_id == 0 && !playlist) {
        metadata = (MetaData *) g_new0(MetaData, 1);
        metadata->uri = g_strdup(uri);
        if (title != NULL)
            metadata->title = g_strstrip(g_strdup(title));
        if (artist != NULL)
            metadata->artist = g_strstrip(g_strdup(artist));
        if (album != NULL)
            metadata->album = g_strstrip(g_strdup(album));
        g_thread_create(get_cover_art, metadata, FALSE, NULL);
    } else {
        gtk_image_clear(GTK_IMAGE(cover_art));
    }

    g_strlcpy(idledata->media_info, message, 1024);
    g_strlcpy(idledata->display_name, title, 1024);
    g_free(message);

    message = gm_tempname(NULL, "mplayer-af_exportXXXXXX");
    g_strlcpy(idledata->af_export, message, 1024);
    g_free(message);

    message = g_strdup("");
    if (title == NULL) {
        title = g_filename_display_basename(uri);
    }
    //buffer = g_markup_printf_escaped("\t<b>%s</b>\n", title);
    //message = g_strconcat(message, buffer, NULL);
    //g_free(buffer);

    if (artist != NULL) {
        buffer = g_markup_printf_escaped("\t<i>%s</i>\n", artist);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    if (album != NULL) {
        buffer = g_markup_printf_escaped("\t%s\n", album);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    g_strlcpy(idledata->media_notification, message, 1024);
    g_free(message);

    if (control_id == 0) {
        set_media_label(idledata);
    } else {
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem_view_info), FALSE);
    }

    if (subtitles)
        gtk_container_forall(GTK_CONTAINER(subtitles), remove_langs, NULL);
    gtk_widget_set_sensitive(GTK_WIDGET(menuitem_edit_select_sub_lang), FALSE);
    if (tracks)
        gtk_container_forall(GTK_CONTAINER(tracks), remove_langs, NULL);
    gtk_widget_set_sensitive(GTK_WIDGET(menuitem_edit_select_audio_lang), FALSE);
    lang_group = NULL;
    audio_group = NULL;


    if (subtitle != NULL) {
        gmtk_media_player_set_attribute_string(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_SUBTITLE_FILE, subtitle);
        g_free(subtitle);
        subtitle = NULL;
    }
    if (audiofile != NULL) {
        gmtk_media_player_set_attribute_string(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_AUDIO_TRACK_FILE, audiofile);
        g_free(audiofile);
        audiofile = NULL;
    }

    /*
       if (g_ascii_strcasecmp(thread_data->filename, "") != 0) {
       if (!device_name(thread_data->filename) && !streaming_media(thread_data->filename)) {
       if (!g_file_test(thread_data->filename, G_FILE_TEST_EXISTS)) {
       error_msg = g_strdup_printf("%s not found\n", thread_data->filename);
       dialog =
       gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
       GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error_msg);
       gtk_window_set_title(GTK_WINDOW(dialog), "GNOME MPlayer Error");
       gtk_dialog_run(GTK_DIALOG(dialog));
       gtk_widget_destroy(dialog);
       return 1;
       }
       }
       }
     */
#ifdef GTK2_12_ENABLED
#ifdef GIO_ENABLED
    // don't put it on the recent list, if it is running in plugin mode
    if (control_id == 0 && !streaming_media(uri)) {
        recent_data = (GtkRecentData *) g_new0(GtkRecentData, 1);
        if (artist != NULL && strlen(artist) > 0) {
            recent_data->display_name = g_strdup_printf("%s - %s", artist, title);
        } else {
            recent_data->display_name = g_strdup(title);
        }
        g_strlcpy(idledata->display_name, recent_data->display_name, 1024);


        file = g_file_new_for_uri(uri);
        file_info = g_file_query_info(file,
                                      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
                                      G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, NULL);


        if (file_info) {
            recent_data->mime_type = g_strdup(g_file_info_get_content_type(file_info));
            g_object_unref(file_info);
        }
        g_object_unref(file);
        recent_data->app_name = g_strdup("gnome-mplayer");
        recent_data->app_exec = g_strdup("gnome-mplayer %u");
        if (recent_data->mime_type != NULL) {
            gtk_recent_manager_add_full(recent_manager, uri, recent_data);
            g_free(recent_data->mime_type);
        }
        g_free(recent_data->app_name);
        g_free(recent_data->app_exec);
        g_free(recent_data);

    }
#endif
#endif
    g_free(title);
    g_free(artist);
    g_free(album);
    if (demuxer != NULL) {
        g_strlcpy(idledata->demuxer, demuxer, 64);
        g_free(demuxer);
    } else {
        g_strlcpy(idledata->demuxer, "", 64);
    }

    last_x = 0;
    last_y = 0;
    idledata->width = width;
    idledata->height = height;

    idledata->retry_on_full_cache = FALSE;
    idledata->cachepercent = -1.0;
    g_strlcpy(idledata->info, uri, 1024);
    set_media_info(idledata);

    streaming = 0;

    gm_store = gm_pref_store_new("gnome-mplayer");
    forcecache = gm_pref_store_get_boolean(gm_store, FORCECACHE);
    gm_pref_store_free(gm_store);


    if (g_ascii_strcasecmp(uri, "dvdnav://") == 0) {
        gtk_widget_show(menu_event_box);
    } else {
        gtk_widget_hide(menu_event_box);
    }

    if (autostart) {
        g_idle_add(hide_buttons, idledata);
        js_state = STATE_PLAYING;

        if (g_str_has_prefix(uri, "mmshttp") || g_str_has_prefix(uri, "http") || g_str_has_prefix(uri, "mms")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_NETWORK);
        } else if (g_str_has_prefix(uri, "dvd") || g_str_has_prefix(uri, "dvdnav")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVD);
        } else if (g_str_has_prefix(uri, "cdda")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_CD);
        } else if (g_str_has_prefix(uri, "cddb")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_CD);
        } else if (g_str_has_prefix(uri, "vcd")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_VCD);
        } else if (g_str_has_prefix(uri, "tv")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_TV);
        } else if (g_str_has_prefix(uri, "dvb")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVB);
        } else if (g_str_has_prefix(uri, "file")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_FILE);
        } else {
            // if all else fails it must be a network type
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_NETWORK);
        }

        gmtk_media_player_set_attribute_boolean(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_PLAYLIST, playlist);
        gmtk_media_player_set_uri(GMTK_MEDIA_PLAYER(media), uri);
        gmtk_media_player_set_state(GMTK_MEDIA_PLAYER(media), MEDIA_STATE_PLAY);

    }

    return 0;
}
Exemple #23
0
/* Helper for gtkhtml_editor_update_context() */
static void
editor_spell_checkers_foreach (GtkhtmlSpellChecker *checker,
                               GtkhtmlEditor *editor)
{
	const GtkhtmlSpellLanguage *language;
	const gchar *language_code;
	GtkActionGroup *action_group;
	GtkUIManager *manager;
	GtkHTML *html;
	GList *list;
	gchar *path;
	gchar *word;
	gint count = 0;
	guint merge_id;

	language = gtkhtml_spell_checker_get_language (checker);
	language_code = gtkhtml_spell_language_get_code (language);

	html = gtkhtml_editor_get_html (editor);
	word = html_engine_get_spell_word (html->engine);
	list = gtkhtml_spell_checker_get_suggestions (checker, word, -1);

	manager = gtkhtml_editor_get_ui_manager (editor);
	action_group = editor->priv->suggestion_actions;
	merge_id = editor->priv->spell_suggestions_merge_id;

	path = g_strdup_printf (
		"/context-menu/context-spell-suggest/"
		"context-spell-suggest-%s-menu", language_code);

	while (list != NULL) {
		gchar *suggestion = list->data;
		gchar *action_name;
		gchar *action_label;
		GtkAction *action;
		GtkWidget *child;
		GSList *proxies;

		/* Action name just needs to be unique. */
		action_name = g_strdup_printf (
			"suggest-%s-%d", language_code, count++);

		action_label = g_markup_printf_escaped (
			"<b>%s</b>", suggestion);

		action = gtk_action_new (
			action_name, action_label, NULL, NULL);

		g_object_set_data_full (
			G_OBJECT (action), "word",
			g_strdup (suggestion), g_free);

		g_signal_connect (
			action, "activate", G_CALLBACK (
			action_context_spell_suggest_cb), editor);

		gtk_action_group_add_action (action_group, action);

		gtk_ui_manager_add_ui (
			manager, merge_id, path,
			action_name, action_name,
			GTK_UI_MANAGER_AUTO, FALSE);

		/* XXX GtkAction offers no supports for Pango markup,
		 *     so we have to manually set "use-markup" on the
		 *     child of the proxy widget. */
		gtk_ui_manager_ensure_update (manager);
		proxies = gtk_action_get_proxies (action);
		child = gtk_bin_get_child (proxies->data);
		g_object_set (child, "use-markup", TRUE, NULL);

		g_free (suggestion);
		g_free (action_name);
		g_free (action_label);

		list = g_list_delete_link (list, list);
	}

	g_free (path);
	g_free (word);
}
Exemple #24
0
static gint prefs_actions_clist_set_row(gint row)
{
	const gchar *entry_text;
	gint len, action_nb;
	gchar action[PREFSBUFSIZE];
	gchar *new_action;

	GET_ENTRY(actions.name_entry);
	if (entry_text[0] == '\0') {
		alertpanel_error(_("Menu name is not set."));
		return -1;
	}

	if (entry_text[0] == '/') {
		alertpanel_error(_("A leading '/' is not allowed in the menu name."));
		return -1;
	}

	if (strchr(entry_text, ':')) {
		alertpanel_error(_("Colon ':' is not allowed in the menu name."));
		return -1;
	}

	action_nb = prefs_actions_find_by_name(entry_text);
	if ((action_nb != -1) && ((row == -1) || (row != action_nb + 1))) {
		alertpanel_error(_("There is an action with this name already."));
		return -1;
	}
	
	strncpy(action, entry_text, PREFSBUFSIZE - 1);

	while (strstr(action, "//")) {
		char *to_move = strstr(action, "//")+1;
		char *where = strstr(action, "//");
		int old_len = strlen(action);
		memmove(where, to_move, strlen(to_move));
		action[old_len-1] = '\0';
	}
	
	g_strstrip(action);

	/* Keep space for the ': ' delimiter */
	len = strlen(action) + 2;
	if (len >= PREFSBUFSIZE - 1) {
		alertpanel_error(_("Menu name is too long."));
		return -1;
	}

	strcat(action, ": ");

	GET_ENTRY(actions.cmd_entry);

	if (entry_text[0] == '\0') {
		alertpanel_error(_("Command-line not set."));
		return -1;
	}

	if (len + strlen(entry_text) >= PREFSBUFSIZE - 1) {
		alertpanel_error(_("Menu name and command are too long."));
		return -1;
	}

	if (action_get_type(entry_text) == ACTION_ERROR) {
		gchar *message;
		message = g_markup_printf_escaped(_("The command\n%s\nhas a syntax error."),
						entry_text);
		alertpanel_error("%s", message);
		g_free(message);
		return -1;
	}

	strcat(action, entry_text);

	new_action = g_strdup(action);	
	prefs_actions_list_view_insert_action(actions.actions_list_view,
	                                      row, new_action, TRUE);
						
	prefs_actions_set_list();

	return 0;
}
Exemple #25
0
void linphone_gtk_call_log_display_missed_call(int nb){
	GtkWidget *mw = linphone_gtk_get_main_window();
	GtkWidget *label = linphone_gtk_get_widget(mw, "history_tab_label");
	gchar *buf = g_markup_printf_escaped(_("<b>Recent calls (%i)</b>"), nb);
	gtk_label_set_markup(GTK_LABEL(label), buf);
}
//!
//! @brief Callback to update the install dialog progress.  The data passed to it should be
//!        in the form of a LwDictInst.  If it is NULL, the progress window will be closed.
//!
G_MODULE_EXPORT gboolean 
gw_installprogresswindow_update_ui_timeout (gpointer data)
{
    //Sanity check
    g_assert (data != NULL);

    //Declarations
    GwInstallProgressWindow *window;
    GwInstallProgressWindowPrivate *priv;
    GtkWindow *settingswindow;
    GwApplication *application;
    LwDictInstList *dictinstlist;
    GwDictInfoList *dictinfolist;
    LwDictInst *di;
    GList *iter;
    int current_to_install;
    int total_to_install;
    char *text_installing;
    char *text_installing_markup;
    char *text_left;
    char *text_left_markup;
    char *text_progressbar;

    //Initializations
    window = GW_INSTALLPROGRESSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_INSTALLPROGRESSWINDOW));
    if (window == NULL) return FALSE;
    application = gw_window_get_application (GW_WINDOW (window));
    dictinstlist = gw_application_get_dictinstlist (application);
    priv = window->priv;
    current_to_install = 0;
    total_to_install = 0;

    //The install is complete close the window
    if (priv->di == NULL)
    {
      settingswindow = gtk_window_get_transient_for (GTK_WINDOW (window));
      dictinfolist = gw_application_get_dictinfolist (application);

      gw_dictinfolist_reload (dictinfolist);

      gtk_widget_destroy (GTK_WIDGET (window));

      gw_application_handle_error (application, GTK_WINDOW (settingswindow), TRUE, NULL);

      lw_dictinstlist_set_cancel_operations (dictinstlist, FALSE);
      gw_settingswindow_check_for_dictionaries (GW_SETTINGSWINDOW (settingswindow));

      return FALSE;
    }

    g_mutex_lock (priv->mutex);

    //Calculate the number of dictionaries left to install
    for (iter = dictinstlist->list; iter != NULL; iter = iter->next)
    {
      di = LW_DICTINST (iter->data);
      if (di != NULL && di->selected)
      {
        current_to_install++;
      }
      if (iter->data == priv->di) break;
    }

    //Calculate the number of dictionaries left to install
    for (iter = dictinstlist->list; iter != NULL; iter = iter->next)
    {
      di = LW_DICTINST (iter->data);
      if (di->selected)
      {
        total_to_install++;
      }
    }
    
    di = priv->di;

    text_progressbar =  g_markup_printf_escaped (gettext("Installing %s..."), di->filename);
    text_left = g_strdup_printf (gettext("Installing dictionary %d of %d..."), current_to_install, total_to_install);
    text_left_markup = g_markup_printf_escaped ("<big><b>%s</b></big>", text_left);
    text_installing = lw_dictinst_get_status_string (di, TRUE);
    text_installing_markup = g_markup_printf_escaped ("<small>%s</small>", text_installing);

    gtk_label_set_markup (priv->label, text_left_markup);
    gtk_label_set_markup (priv->sublabel, text_installing_markup);
    gtk_progress_bar_set_fraction (priv->progressbar, priv->install_fraction);
    gtk_progress_bar_set_text (priv->progressbar, text_progressbar);

    g_mutex_unlock (priv->mutex);

    //Cleanup
    g_free (text_progressbar);
    g_free (text_left);
    g_free (text_left_markup);
    g_free (text_installing);
    g_free (text_installing_markup);

    return TRUE;
}
Exemple #27
0
void
clock_utils_display_help (GtkWidget  *widget,
			  const char *doc_id,
			  const char *link_id)
{
	GError *error = NULL;
	char   *uri;

	if (link_id)
		uri = g_strdup_printf ("help:%s/%s", doc_id, link_id);
	else
		uri = g_strdup_printf ("help:%s", doc_id);

	gtk_show_uri (gtk_widget_get_screen (widget), uri,
		      gtk_get_current_event_time (), &error);

	g_free (uri);

	if (error &&
	    g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
		g_error_free (error);
	else if (error) {
		GtkWidget *parent;
		GtkWidget *dialog;
		char      *primary;

		if (GTK_IS_WINDOW (widget))
			parent = widget;
		else
			parent = NULL;

		primary = g_markup_printf_escaped (
				_("Could not display help document '%s'"),
				doc_id);
		dialog = gtk_message_dialog_new (
				parent ? GTK_WINDOW (parent) : NULL,
				GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_CLOSE,
				"%s", primary);

		gtk_message_dialog_format_secondary_text (
					GTK_MESSAGE_DIALOG (dialog),
					"%s", error->message);

		g_error_free (error);
		g_free (primary);

		g_signal_connect (dialog, "response",
				  G_CALLBACK (gtk_widget_destroy),
				  NULL);

		gtk_window_set_icon_name (GTK_WINDOW (dialog), CLOCK_ICON);
		gtk_window_set_screen (GTK_WINDOW (dialog),
				       gtk_widget_get_screen (widget));

		if (parent == NULL) {
			/* we have no parent window */
			gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog),
							  FALSE);
			gtk_window_set_title (GTK_WINDOW (dialog),
					      _("Error displaying help document"));
		}

		gtk_widget_show (dialog);
	}
}
static void
trash_empty_start ()
{
        GtkWidget *vbox1, *vbox2, *hbox;
        GtkWidget *label1, *label3;
        gchar *markup;
        GCancellable *cancellable;

        trash_empty_dialog = gtk_dialog_new ();
        gtk_window_set_default_size (GTK_WINDOW (trash_empty_dialog), 400, -1);
        gtk_window_set_icon_name (GTK_WINDOW (trash_empty_dialog), "user-trash");
        gtk_window_set_title (GTK_WINDOW (trash_empty_dialog),
                              _("Emptying the trash"));

        vbox1 = gtk_vbox_new (FALSE, 12);
        vbox2 = gtk_vbox_new (FALSE, 0);
        hbox = gtk_hbox_new (FALSE, 0);

        label1 = gtk_label_new (NULL);
        gtk_label_set_line_wrap (GTK_LABEL (label1), TRUE);
        gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5);

        label3 = gtk_label_new (NULL);
        gtk_label_set_line_wrap (GTK_LABEL (label3), TRUE);
        gtk_misc_set_alignment (GTK_MISC (label3), 0.0, 0.5);
        gtk_widget_hide (label3);

        location_label = gtk_label_new (NULL);
        gtk_label_set_line_wrap (GTK_LABEL (location_label), TRUE);
        gtk_misc_set_alignment (GTK_MISC (location_label), 0.0, 0.5);

        file_label = gtk_label_new (NULL);
        gtk_label_set_line_wrap (GTK_LABEL (file_label), TRUE);
        gtk_misc_set_alignment (GTK_MISC (file_label), 0.0, 0.5);

        progressbar = gtk_progress_bar_new ();
        gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (progressbar), 0.1);
        gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar), _("Preparing to empty trash…"));

        gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (trash_empty_dialog))), vbox1, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (vbox1), label1, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (hbox), label3, FALSE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (hbox), location_label, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (vbox2), progressbar, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (vbox2), file_label, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0);

        gtk_widget_show (label1);
        gtk_widget_show (vbox1);
        gtk_widget_show_all (vbox2);
        gtk_widget_show (hbox);
        gtk_widget_show (location_label);

        gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (trash_empty_dialog))), 6);
        gtk_container_set_border_width (GTK_CONTAINER (vbox1), 6);

        gtk_dialog_add_button (GTK_DIALOG (trash_empty_dialog),
                               GTK_STOCK_CANCEL,
                               GTK_RESPONSE_CANCEL);

        markup = g_markup_printf_escaped ("<big><b>%s</b></big>", _("Emptying the trash"));
        gtk_label_set_markup (GTK_LABEL (label1), markup);
        /* Translators: "Emptying trash from <device>" */
        gtk_label_set_text (GTK_LABEL (label3), _("From: "));

        cancellable = g_cancellable_new ();
        g_signal_connect_object (trash_empty_dialog, "response",
                                 G_CALLBACK (g_cancellable_cancel),
                                 cancellable, G_CONNECT_SWAPPED);
        g_io_scheduler_push_job (trash_empty_job, NULL, NULL, 0, cancellable);

        gtk_widget_show (trash_empty_dialog);

        g_free (markup);
        g_object_unref (cancellable);
}
gchar*
codeslayer_xml_serialize_gobjects (GList      *objects,
                                   gpointer    name, 
                                   GHashTable *table)
{
  GString *xml;
  GList *keys; 
  
  xml = g_string_new ("<");
  xml = g_string_append (xml, name);
  xml = g_string_append (xml, "s>\n");

  keys = g_hash_table_get_keys (table);
  
  while (objects != NULL)
    {
      GObject *object = objects->data;
      GList *list; 
      
      xml = g_string_append (xml, "\t<");
      xml = g_string_append (xml, name);
      
      list = keys;
      
      while (list != NULL)
        {
          gchar *property = list->data;
          GType *type = (GType*)g_hash_table_lookup (table, property);
          
          if (*type == G_TYPE_STRING)
            {
              gchar *val;
              gchar *attr; 
              g_object_get (object, property, &val, NULL);  
              xml = g_string_append (xml, " ");
              xml = g_string_append (xml, property);
              attr = g_markup_printf_escaped ("=\"%s", val);
              xml = g_string_append (xml, attr);
              xml = g_string_append (xml, "\"");
              g_free (val);         
              g_free (attr);         
            }              
          else if (*type == G_TYPE_BOOLEAN)
            {
              gboolean val;
              gchar *attr; 
              g_object_get (object, property, &val, NULL);  
              xml = g_string_append (xml, " ");
              xml = g_string_append (xml, property);
              attr = g_markup_printf_escaped ("=\"%d", val);
              xml = g_string_append (xml, attr);
              xml = g_string_append (xml, "\"");
              g_free (attr);         
            }              
          else if (*type == G_TYPE_INT)
            {
              gint val;
              gchar *attr; 
              g_object_get (object, property, &val, NULL);
              xml = g_string_append (xml, " ");
              xml = g_string_append (xml, property);
              attr = g_markup_printf_escaped ("=\"%d", val);
              xml = g_string_append (xml, attr);
              xml = g_string_append (xml, "\"");
              g_free (attr);
            }
                        
          list = g_list_next (list);          
        }
      
      xml = g_string_append (xml, "/>\n");

      objects = g_list_next (objects);
    }
    
  g_list_free (keys);

  xml = g_string_append (xml, "</");
  xml = g_string_append (xml, name);
  xml = g_string_append (xml, "s>");

  return g_string_free (xml, FALSE);
}
Exemple #30
0
static void
interface_generate (GIdlWriter * writer, GIdlNodeInterface * node)
{
  GList *l;
  char *markup;
  if (node->node.type == G_IDL_NODE_OBJECT)
    {
      markup =
	g_markup_printf_escaped ("<object name=\"%s\" "
				 "parent=\"%s\" "
				 "type-name=\"%s\" "
				 "get-type=\"%s\">\n",
				 node->node.name,
				 node->parent,
				 node->gtype_name,
				 node->gtype_init);
    }
  else if (node->node.type == G_IDL_NODE_INTERFACE)
    {
      markup =
	g_markup_printf_escaped
	("<interface name=\"%s\" type-name=\"%s\" get-type=\"%s\">\n",
	 node->node.name, node->gtype_name, node->gtype_init);
    }

  g_writer_write_indent (writer, markup);
  g_free (markup);
  if (node->node.type == G_IDL_NODE_OBJECT && node->interfaces != NULL)
    {
      GList *l;
      g_writer_write_indent (writer, "<implements>\n");
      for (l = node->interfaces; l != NULL; l = l->next)
	{
	  markup =
	    g_markup_printf_escaped ("<interface name=\"%s\"/>\n",
				     (char *) l->data);
	  g_writer_write (writer, markup);
	  g_free (markup);
	}
      g_writer_write_unindent (writer, "</implements>\n");
    }
  else if (node->node.type == G_IDL_NODE_INTERFACE
	   && node->prerequisites != NULL)
    {
      GList *l;
      g_writer_write_indent (writer, "<requires>\n");
      for (l = node->prerequisites; l != NULL; l = l->next)
	{
	  markup =
	    g_markup_printf_escaped ("<interface name=\"%s\"/>\n",
				     (char *) l->data);
	  g_writer_write (writer, markup);
	  g_free (markup);
	}
      g_writer_write_unindent (writer, "</requires>\n");
    }

  for (l = node->members; l != NULL; l = l->next)
    {
      node_generate (writer, l->data);
    }

  if (node->node.type == G_IDL_NODE_OBJECT)
    {
      g_writer_write_unindent (writer, "</object>\n");
    }
  else if (node->node.type == G_IDL_NODE_INTERFACE)
    {
      g_writer_write_unindent (writer, "</interface>\n");
    }
}