diff options
author | Wu Xiaotian <[email protected]> | 2019-07-29 22:52:14 +0800 |
---|---|---|
committer | raveit65 <[email protected]> | 2019-08-01 18:55:17 +0200 |
commit | 5e0c0f43be12a992875bd68121371d157eb2ccbb (patch) | |
tree | 3eb00e932cbc596cc64c4cbf5bfca9ffe3e0c0cf /capplets | |
parent | fb11796fa9fe0250cc43f2cc8e5315f4b3700b5d (diff) | |
download | mate-control-center-5e0c0f43be12a992875bd68121371d157eb2ccbb.tar.bz2 mate-control-center-5e0c0f43be12a992875bd68121371d157eb2ccbb.tar.xz |
appearance: add new font for user
Diffstat (limited to 'capplets')
-rw-r--r-- | capplets/appearance/appearance-font.c | 75 | ||||
-rw-r--r-- | capplets/appearance/data/appearance.ui | 32 |
2 files changed, 105 insertions, 2 deletions
diff --git a/capplets/appearance/appearance-font.c b/capplets/appearance/appearance-font.c index 32ba202c..ab8e5938 100644 --- a/capplets/appearance/appearance-font.c +++ b/capplets/appearance/appearance-font.c @@ -28,6 +28,7 @@ #include <glib/gi18n.h> #include <gio/gio.h> #include <gdk/gdkx.h> +#include <glib/gstdio.h> #include "capplet-util.h" @@ -560,6 +561,78 @@ cb_details_response (GtkDialog *dialog, gint response_id) gtk_widget_hide (GTK_WIDGET (dialog)); } +static void install_new_font (const gchar *filepath) +{ + GFile *src, *dst; + gchar *fontdir, *fontpath; + char *basename; + GError *error = NULL; + + fontdir = g_build_filename (g_get_home_dir(), ".fonts", NULL); + if (!g_file_test (fontdir, G_FILE_TEST_IS_DIR)) + { + if(g_mkdir (fontdir, 0755) != 0) { + g_free (fontdir); + return; + } + } + g_free (fontdir); + + basename = g_path_get_basename (filepath); + fontpath = g_build_filename (g_get_home_dir(), ".fonts", basename, NULL); + g_free (basename); + src = g_file_new_for_path (filepath); + dst = g_file_new_for_path (fontpath); + + if (!g_file_copy (src, + dst, + G_FILE_COPY_NONE, + NULL, + NULL, + NULL, + &error)) { + g_warning ("install new font failed: %s\n", error->message); + g_error_free (error); + } + g_object_unref (src); + g_object_unref (dst); +} + +static void +cb_add_new_font (GtkWidget *button, + AppearanceData *data) +{ + GtkWidget *dialog; + GtkFileFilter *filter; + GtkFileChooser *chooser; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; + gint res; + + dialog = gtk_file_chooser_dialog_new (_("Select Font"), + GTK_WINDOW (appearance_capplet_get_widget (data, "appearance_window")), + action, + _("_Cancel"), + GTK_RESPONSE_CANCEL, + _("_Open"), + GTK_RESPONSE_ACCEPT, + NULL); + chooser = GTK_FILE_CHOOSER (dialog); + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Fonts")); + gtk_file_filter_add_mime_type (filter, "font/ttf"); + gtk_file_chooser_add_filter (chooser, filter); + + res = gtk_dialog_run (GTK_DIALOG (dialog)); + if (res == GTK_RESPONSE_ACCEPT) + { + char *filename; + filename = gtk_file_chooser_get_filename (chooser); + install_new_font (filename); + g_free (filename); + } + gtk_widget_destroy (dialog); +} + static void cb_show_details (GtkWidget *button, AppearanceData *data) @@ -705,6 +778,8 @@ void font_init(AppearanceData* data) G_CALLBACK (marco_changed), data); + g_signal_connect (appearance_capplet_get_widget (data, "add_new_font"), "clicked", G_CALLBACK (cb_add_new_font), data); + marco_titlebar_load_sensitivity(data); setup_font_pair(appearance_capplet_get_widget(data, "monochrome_radio"), appearance_capplet_get_widget (data, "monochrome_sample"), ANTIALIAS_NONE, HINT_FULL); diff --git a/capplets/appearance/data/appearance.ui b/capplets/appearance/data/appearance.ui index 2032e05d..ad45e61b 100644 --- a/capplets/appearance/data/appearance.ui +++ b/capplets/appearance/data/appearance.ui @@ -2566,6 +2566,34 @@ Author: Wolfgang Ulbrich </packing> </child> <child> + <object class="GtkButtonBox" id="hbuttonbox5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="add_new_font"> + <property name="label" translatable="yes">Add new f_ont...</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> <object class="GtkBox" id="vbox6"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -2795,7 +2823,7 @@ Author: Wolfgang Ulbrich <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> <child> @@ -2823,7 +2851,7 @@ Author: Wolfgang Ulbrich <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">2</property> + <property name="position">3</property> </packing> </child> </object> |