示例#1
0
void uri_opener_open(MessageView *msgview, GSList *uris)
{
	cm_return_if_fail(msgview);
	cm_return_if_fail(msgview->mimeview);
	cm_return_if_fail(msgview->mimeview->textview);
	cm_return_if_fail(msgview);
	if (!opener.window)
		uri_opener_create();

	manage_window_set_transient(GTK_WINDOW(opener.window));
	gtk_widget_grab_focus(opener.close_btn);
	
	if (uris == NULL) {
		alertpanel_notice(_("There are no URLs in this email."));
		return;
	}
	
	opener.msgview = msgview;
	opener.uris = g_slist_copy(uris);
	uri_opener_load_uris();

	gtk_widget_show(opener.window);
	gtk_widget_grab_focus(opener.urilist);
	gtk_window_set_modal(GTK_WINDOW(opener.window), TRUE);
}
示例#2
0
static void prefs_themes_btn_remove_clicked_cb(GtkWidget *widget, gpointer data)
{
	ThemesData *tdata = prefs_themes_data;
	gchar      *theme_str;
	gchar      *alert_title = NULL;
	AlertValue  val = 0;
	gchar      *tmp = NULL;

	theme_str = tdata->displayed;

	tmp = g_path_get_basename(theme_str);

	if (IS_SYSTEM_THEME(theme_str)) {
		if (!superuser_p()) {
			alertpanel_error(_("Only root can remove system themes"));
			return;
		}
		alert_title = g_strdup_printf(_("Remove system theme '%s'"), tmp);
	}
	if (NULL == alert_title) {
		alert_title = g_strdup_printf(_("Remove theme '%s'"), tmp);
	}

	g_free(tmp);

	val = alertpanel(alert_title,
			 _("Are you sure you want to remove this theme?"),
			 GTK_STOCK_NO, GTK_STOCK_YES, NULL);
	g_free(alert_title);

	if (G_ALERTALTERNATE == val) {
		gchar *status = NULL;

		prefs_themes_foreach_file(theme_str, prefs_themes_file_remove, &status); 
		if (0 != rmdir(theme_str)) {
			if (status != NULL) {
				alertpanel_error(_("File %s failed\nwhile removing theme."), status);
				g_free(status);
			}
			else
				alertpanel_error(_("Removing theme directory failed."));
		}
		else {	
			alertpanel_notice(_("Theme removed successfully"));
			/* update interface back to first theme */
			prefs_themes_get_themes_and_names(tdata);
			prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
			prefs_themes_display_global_stats(tdata);
			tdata->displayed = (gchar *)((g_list_first(tdata->themes))->data);
			prefs_themes_get_theme_info(tdata);
		}
	}
}
示例#3
0
static void cache_clean_button_clicked_cb(GtkButton *button, gpointer data)
{
	GtkLabel *label = (GtkLabel *) data;
	gint val = 0;
	AvatarCleanupResult *acr;
	guint misses;

	val = alertpanel_full(_("Clear icon cache"),
			_("Are you sure you want to remove all cached avatar icons?"),
			GTK_STOCK_NO, GTK_STOCK_YES, NULL, FALSE,
			NULL, ALERT_WARNING, G_ALERTDEFAULT);
	if (val != G_ALERTALTERNATE)
		return;

	debug_print("cleaning missing cache");
	misses = g_hash_table_size(libravatarmisses);
	g_hash_table_remove_all(libravatarmisses);

	debug_print("cleaning disk cache");
	acr = libravatar_cache_clean();
	if (acr == NULL) {
		alertpanel_error(_("Not enough memory for operation"));
		return;
	}

	if (acr->e_stat == 0 && acr->e_unlink == 0) {
		alertpanel_notice(_("Icon cache successfully cleared:\n"
			"• %u missing entries removed.\n"
			"• %u files removed."),
			misses, acr->removed);
		gtk_label_set_markup(label,
			_("<span color=\"#006400\">Icon cache succesfully cleared!</span>"));
	}
	else {
		alertpanel_warning(_("Errors clearing icon cache:\n"
			"• %u missing entries removed.\n"
			"• %u files removed.\n"
			"• %u files failed to be read.\n"
			"• %u files couldn't be removed."),
			misses, acr->removed, acr->e_stat, acr->e_unlink);
		gtk_label_set_markup(label,
			_("<span color=\"red\">Error clearing icon cache.</span>"));
	}
	gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
	g_free(acr);
}
示例#4
0
static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data)
{
	gchar      *filename, *source;
	gchar 	   *themeinfo, *themename;
	gchar      *alert_title = NULL;
	CopyInfo   *cinfo;
	AlertValue  val = 0;
	ThemesData *tdata = prefs_themes_data;

	filename = filesel_select_file_open_folder(_("Select theme folder"), NULL);
	if (filename == NULL) 
		return;

	if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR)
		filename = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL);
	else
		filename = g_strdup(filename);

	cinfo = g_new0(CopyInfo, 1);
	source = g_path_get_dirname(filename);
	themename = g_path_get_basename(source);
	debug_print("Installing '%s' theme from %s\n", themename, filename);

	themeinfo = g_strconcat(source, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
	alert_title = g_strdup_printf(_("Install theme '%s'"), themename);
	if (file_exist(themeinfo, FALSE) == FALSE) {
		val = alertpanel(alert_title,
				 _("This folder doesn't seem to be a theme folder.\nInstall anyway?"),
				 GTK_STOCK_NO, GTK_STOCK_YES, NULL);
		if (G_ALERTALTERNATE != val)
			goto end_inst;
	}
	if (superuser_p ()) {
		val = alertpanel(alert_title,
				 _("Do you want to install theme for all users?"),
				 GTK_STOCK_NO, GTK_STOCK_YES, NULL);
		switch (val) {
		case G_ALERTALTERNATE:
			cinfo->dest = stock_pixmap_get_system_theme_dir_for_theme(
						themename);
			break;
		case G_ALERTDEFAULT:
			break;
		default:
			goto end_inst;
		}
	}
	g_free(alert_title);
	if (cinfo->dest == NULL) {
		cinfo->dest = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
					  PIXMAP_THEME_DIR, G_DIR_SEPARATOR_S,
					  themename, NULL);
	}
	if (TRUE == is_dir_exist(cinfo->dest)) {
		AlertValue val = alertpanel_full(_("Theme exists"),
				_("A theme with the same name is\nalready installed in this location.\n\n"
				  "Do you want to replace it?"),
				GTK_STOCK_CANCEL, _("Overwrite"), NULL, FALSE,
				NULL, ALERT_WARNING, G_ALERTDEFAULT);
		if (val == G_ALERTALTERNATE) {
			if (remove_dir_recursive(cinfo->dest) < 0) {
				alertpanel_error(_("Couldn't delete the old theme in %s."), cinfo->dest);
				goto end_inst;
			}
		} else {
			goto end_inst;
		}
	}
	if (0 != make_dir_hier(cinfo->dest)) {
		alertpanel_error(_("Couldn't create destination directory %s."), cinfo->dest);
		goto end_inst;
	}
	prefs_themes_foreach_file(source, prefs_themes_file_install, cinfo);
	if (cinfo->status == NULL) {
		GList *insted;

		/* update interface to show newly installed theme */
		prefs_themes_get_themes_and_names(tdata);
		insted = g_list_find_custom(tdata->themes, 
					    (gpointer)(cinfo->dest), 
					    (GCompareFunc)strcmp2);
		if (NULL != insted) {
			alertpanel_notice(_("Theme installed successfully."));
			tdata->displayed = (gchar *)(insted->data);
			prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
			prefs_themes_display_global_stats(tdata);
			prefs_themes_get_theme_info(tdata);
		}
		else
			alertpanel_error(_("Failed installing theme"));
	}
	else
		alertpanel_error(_("File %s failed\nwhile installing theme."), cinfo->status);
end_inst:
	g_free(cinfo->dest);
	g_free(filename);
	g_free(source);
	g_free(themeinfo);
	g_free(cinfo);
	g_free(themename);
}
示例#5
0
void sgpgme_create_secret_key(PrefsAccount *account, gboolean ask_create)
{
	AlertValue val = G_ALERTDEFAULT;
	gchar *key_parms = NULL;
	gchar *name = NULL;
	gchar *email = NULL;
	gchar *passphrase = NULL, *passphrase_second = NULL;
	gint prev_bad = 0;
	gchar *tmp = NULL;
	gpgme_error_t err = 0;
	gpgme_ctx_t ctx;
	GtkWidget *window = NULL;
	gpgme_genkey_result_t key;

	if (account == NULL)
		account = account_get_default();

	if (account->address == NULL) {
		alertpanel_error(_("You have to save the account's information with \"OK\" "
				   "before being able to generate a key pair.\n"));
		return;
	}
	if (ask_create) {
		val = alertpanel(_("No PGP key found"),
				_("Claws Mail did not find a secret PGP key, "
				  "which means that you won't be able to sign "
				  "emails or receive encrypted emails.\n"
				  "Do you want to create a new key pair now?"),
				  GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
		if (val == G_ALERTDEFAULT) {
			prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
			prefs_gpg_save_config();
			return;
		}
	}

	if (account->name) {
		name = g_strdup(account->name);
	} else {
		name = g_strdup(account->address);
	}
	email = g_strdup(account->address);
	tmp = g_strdup_printf("%s <%s>", account->name?account->name:account->address, account->address);
again:
	passphrase = passphrase_mbox(tmp, NULL, prev_bad, 1);
	if (passphrase == NULL) {
		g_free(tmp);
		g_free(email);
		g_free(name);		
		return;
	}
	passphrase_second = passphrase_mbox(tmp, NULL, 0, 2);
	if (passphrase_second == NULL) {
		g_free(tmp);
		g_free(email);
		g_free(passphrase);		
		g_free(name);		
		return;
	}
	if (strcmp(passphrase, passphrase_second)) {
		g_free(passphrase);
		g_free(passphrase_second);
		prev_bad = 1;
		goto again;
	}
	
	key_parms = g_strdup_printf("<GnupgKeyParms format=\"internal\">\n"
					"Key-Type: RSA\n"
					"Key-Length: 2048\n"
					"Subkey-Type: RSA\n"
					"Subkey-Length: 2048\n"
					"Name-Real: %s\n"
					"Name-Email: %s\n"
					"Expire-Date: 0\n"
					"%s%s%s"
					"</GnupgKeyParms>\n",
					name, email, 
					strlen(passphrase)?"Passphrase: ":"",
					passphrase,
					strlen(passphrase)?"\n":"");
#ifndef G_PLATFORM_WIN32
	if (mlock(passphrase, strlen(passphrase)) == -1)
		debug_print("couldn't lock passphrase\n");
	if (mlock(passphrase_second, strlen(passphrase_second)) == -1)
		debug_print("couldn't lock passphrase2\n");
#endif
	g_free(tmp);
	g_free(email);
	g_free(name);
	g_free(passphrase_second);
	g_free(passphrase);
	
	err = gpgme_new (&ctx);
	if (err) {
		alertpanel_error(_("Couldn't generate a new key pair: %s"),
				 gpgme_strerror(err));
		g_free(key_parms);
		return;
	}
	

	window = label_window_create(_("Generating your new key pair... Please move the mouse "
			      "around to help generate entropy..."));

	err = gpgme_op_genkey(ctx, key_parms, NULL, NULL);
	g_free(key_parms);

	label_window_destroy(window);

	if (err) {
		alertpanel_error(_("Couldn't generate a new key pair: %s"), gpgme_strerror(err));
		gpgme_release(ctx);
		return;
	}
	key = gpgme_op_genkey_result(ctx);
	if (key == NULL) {
		alertpanel_error(_("Couldn't generate a new key pair: unknown error"));
		gpgme_release(ctx);
		return;
	} else {
		gchar *buf = g_strdup_printf(_("Your new key pair has been generated. "
				    "Its fingerprint is:\n%s\n\nDo you want to export it "
				    "to a keyserver?"),
				    key->fpr ? key->fpr:"null");
		AlertValue val = alertpanel(_("Key generated"), buf,
				  GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
		g_free(buf);
		if (val == G_ALERTALTERNATE) {
#ifndef G_OS_WIN32
			gchar *cmd = g_strdup_printf("gpg --no-tty --send-keys %s", key->fpr);
			int res = 0;
			pid_t pid = 0;
			pid = fork();
			if (pid == -1) {
				res = -1;
			} else if (pid == 0) {
				/* son */
				res = system(cmd);
				res = WEXITSTATUS(res);
				_exit(res);
			} else {
				int status = 0;
				time_t start_wait = time(NULL);
				res = -1;
				do {
					if (waitpid(pid, &status, WNOHANG) == 0 || !WIFEXITED(status)) {
						usleep(200000);
					} else {
						res = WEXITSTATUS(status);
						break;
					}
					if (time(NULL) - start_wait > 5) {
						debug_print("SIGTERM'ing gpg\n");
						kill(pid, SIGTERM);
					}
					if (time(NULL) - start_wait > 6) {
						debug_print("SIGKILL'ing gpg\n");
						kill(pid, SIGKILL);
						break;
					}
				} while(1);
			}
			if (res == 0) {
				alertpanel_notice(_("Key exported."));
			} else {
				alertpanel_error(_("Couldn't export key."));
			}
			g_free(cmd);
#else
			alertpanel_error(_("Key export isn't implemented in Windows."));
#endif
		}
	}
	prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
	prefs_gpg_save_config();
	gpgme_release(ctx);
}