Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Now preference dialog is mapped with GSettings, new GSettings schema …

…created.
  • Loading branch information...
commit a4b7b783ad17032c0988b75aaf409f89c8b40db0 1 parent 036e320
Damián Nohales authored
6 CMakeLists.txt
@@ -20,4 +20,10 @@ include(ValaVersion)
20 20 find_package(Vala)
21 21 ensure_vala_version("0.11.0" MINIMUM)
22 22
  23 +if(NOT DEFINED USE_GSETTINGS)
  24 + set(USE_GSETTINGS 1)
  25 +endif()
  26 +
23 27 add_subdirectory(src)
  28 +
  29 +unset(USE_GSETTINGS)
1  config.h.in
@@ -4,3 +4,4 @@
4 4 #define GETTEXT_PACKAGE "@GETTEXT_PACKAGE@"
5 5 #define LOCALEDIR "@LOCALEDIR@"
6 6 #define DATADIR "@DATADIR@"
  7 +#define USE_GSETTINGS @USE_GSETTINGS@
12 data/es.nohal.Gablabel.gschema.xml
... ... @@ -0,0 +1,12 @@
  1 +<schemalist>
  2 + <schema id="es.nohal.Gablabel" path="/apps/gablabel/">
  3 + <key name="clipboard-binding" type="s">
  4 + <default>"&lt;Ctrl&gt;&lt;Alt&gt;W"</default>
  5 + <summary>Key binding for translate clipboard text</summary>
  6 + </key>
  7 + <key name="selected-binding" type="s">
  8 + <default>"&lt;Ctrl&gt;&lt;Alt&gt;S"</default>
  9 + <summary>Key binding for translate selected text</summary>
  10 + </key>
  11 + </schema>
  12 +</schemalist>
3  data/gablabel/mainwindow.ui
@@ -68,6 +68,7 @@
68 68 <property name="visible">True</property>
69 69 <property name="can_focus">False</property>
70 70 <property name="use_action_appearance">False</property>
  71 + <property name="use_underline">True</property>
71 72 <property name="use_stock">True</property>
72 73 </object>
73 74 </child>
@@ -102,7 +103,7 @@ translator does not work well</property>
102 103 </packing>
103 104 </child>
104 105 <child>
105   - <object class="GtkToolButton" id="toolbutton_about">
  106 + <object class="GtkToolButton" id="toolbutton_preferences">
106 107 <property name="visible">True</property>
107 108 <property name="can_focus">False</property>
108 109 <property name="use_action_appearance">False</property>
10 data/gablabel/preferencesdialog.ui
@@ -6,6 +6,7 @@
6 6 <property name="can_focus">False</property>
7 7 <property name="border_width">5</property>
8 8 <property name="title" translatable="yes">Gablabel preferences</property>
  9 + <property name="destroy_with_parent">True</property>
9 10 <property name="type_hint">dialog</property>
10 11 <child internal-child="vbox">
11 12 <object class="GtkVBox" id="dialog-vbox1">
@@ -57,7 +58,7 @@
57 58 </packing>
58 59 </child>
59 60 <child>
60   - <object class="GtkEntry" id="entry1">
  61 + <object class="GtkEntry" id="entry_clipboard">
61 62 <property name="visible">True</property>
62 63 <property name="can_focus">True</property>
63 64 <property name="invisible_char">●</property>
@@ -73,7 +74,7 @@
73 74 </packing>
74 75 </child>
75 76 <child>
76   - <object class="GtkEntry" id="entry2">
  77 + <object class="GtkEntry" id="entry_selected">
77 78 <property name="visible">True</property>
78 79 <property name="can_focus">True</property>
79 80 <property name="invisible_char">●</property>
@@ -111,7 +112,6 @@
111 112 </child>
112 113 <child>
113 114 <object class="GtkAlignment" id="alignment2">
114   - <property name="visible">True</property>
115 115 <property name="can_focus">False</property>
116 116 <property name="top_padding">10</property>
117 117 <property name="left_padding">5</property>
@@ -187,7 +187,7 @@
187 187 <property name="can_focus">False</property>
188 188 <property name="layout_style">end</property>
189 189 <child>
190   - <object class="GtkButton" id="button1">
  190 + <object class="GtkButton" id="button_close">
191 191 <property name="label">gtk-close</property>
192 192 <property name="visible">True</property>
193 193 <property name="can_focus">True</property>
@@ -211,7 +211,7 @@
211 211 </object>
212 212 </child>
213 213 <action-widgets>
214   - <action-widget response="0">button1</action-widget>
  214 + <action-widget response="0">button_close</action-widget>
215 215 </action-widgets>
216 216 </object>
217 217 </interface>
59 src/Application.vala
@@ -8,18 +8,15 @@ namespace Gablabel
8 8 return Application.singleton_instance;
9 9 }
10 10
11   - enum BindingName {
12   - CLIPBOARD,
13   - SELECTED
14   - }
15   -
16 11 public MainWindow window { get; private set; }
17 12 public StatusIconManager statusIcon { get; private set; }
18 13 public KeyBindingManager keyBindings { get; private set; }
19 14 public GLib.Settings settings { get; private set; }
20   - private Gee.Map<Application.BindingName, string> currentBindings = new Gee.HashMap<Application.BindingName, string>();
  15 + private Gee.Map<string, string> currentBindings = new Gee.HashMap<string, string>();
21 16
22 17 private Application(string[] args){
  18 + Application.singleton_instance = this;
  19 +
23 20 Gtk.init(ref args);
24 21
25 22 Intl.bindtextdomain( Config.GETTEXT_PACKAGE, Config.LOCALEDIR );
@@ -29,19 +26,21 @@ namespace Gablabel
29 26
30 27 public int run(){
31 28 try{
  29 + keyBindings = new KeyBindingManager();
  30 +
  31 + if(Config.USE_GSETTINGS == 1){
  32 + settings = new GLib.Settings("es.nohal.Gablabel");
  33 + on_settings_changed("clipboard-binding");
  34 + on_settings_changed("selected-binding");
  35 + settings.changed.connect(on_settings_changed);
  36 + }
  37 +
32 38 window = new Gablabel.MainWindow();
33 39 statusIcon = new StatusIconManager(window);
  40 +
34 41 window.start();
35 42 statusIcon.start();
36 43
37   - keyBindings = new KeyBindingManager();
38   - keyBindings.bind("<Ctrl><Alt>S", (event) => {
39   - statusIcon.on_selected_activated();
40   - });
41   -
42   - settings = new GLib.Settings("es.nohal.gablabel");
43   - settings.changed
44   -
45 44 Gtk.main();
46 45 return 0;
47 46 } catch(Error e){
@@ -50,8 +49,36 @@ namespace Gablabel
50 49 }
51 50 }
52 51
53   - private void refreshBindings(){
54   -
  52 + private KeyBindingManager.KeybindingHandlerFunc? handler_func_by_setting(string key)
  53 + {
  54 + switch(key)
  55 + {
  56 + case "clipboard-binding":
  57 + return () => {
  58 + statusIcon.on_clipboard_activated();
  59 + };
  60 + case "selected-binding":
  61 + return () => {
  62 + statusIcon.on_selected_activated();
  63 + };
  64 + default:
  65 + return null;
  66 + }
  67 + }
  68 +
  69 + private void on_settings_changed(string key)
  70 + {
  71 + switch(key)
  72 + {
  73 + case "clipboard-binding":
  74 + case "selected-binding":
  75 + if(currentBindings.has_key(key)){
  76 + keyBindings.unbind(currentBindings[key]);
  77 + }
  78 + currentBindings[key] = settings.get_string(key);
  79 + keyBindings.bind(currentBindings[key], handler_func_by_setting(key));
  80 + break;
  81 + }
55 82 }
56 83
57 84 public static int main(string[] args){
4 src/MainWindow.vala
@@ -27,8 +27,6 @@ namespace Gablabel
27 27 mainMenu = builder.get_object("main_menu") as Menu;
28 28 buttonReload = builder.get_object("toolbutton_reload") as ToolButton;
29 29 menuItemReload = builder.get_object("main_menu_reload") as ImageMenuItem;
30   - AccelMap.add_entry("<Gablabel>/Clipboard", Gdk.keyval_from_name("r"), Gdk.ModifierType.CONTROL_MASK);
31   - menuItemReload.set_accel_path("<Gablabel>/Clipboard");
32 30
33 31 //Signals connection
34 32 this.delete_event.connect(this.hide_on_delete);
@@ -41,6 +39,7 @@ namespace Gablabel
41 39 buttonMainMenu.set_menu(mainMenu);
42 40 buttonMainMenu.clicked.connect(() => { buttonMainMenu.show_menu(); });
43 41 buttonReload.clicked.connect(webView.load_translator);
  42 + (builder.get_object("toolbutton_preferences") as ToolButton).clicked.connect(show_preferences_dialog);
44 43
45 44 (builder.get_object("main_menu_fullscreen") as ImageMenuItem).activate.connect(() => {
46 45 if(this.isFullscreen){
@@ -97,6 +96,7 @@ namespace Gablabel
97 96 dialog.authors = authors;
98 97
99 98 dialog.run();
  99 + dialog.destroy();
100 100 }
101 101
102 102 public void show_preferences_dialog(){
32 src/PreferencesDialogManager.vala
@@ -4,12 +4,14 @@ namespace Gablabel
4 4 {
5 5 public class PreferencesDialogManager
6 6 {
7   - private GLib.Settings settings;
8 7 private Dialog dialog;
9 8 private MainWindow parent;
10 9
11 10 public PreferencesDialogManager(MainWindow parent){
12 11 this.parent = parent;
  12 + }
  13 +
  14 + public void run(){
13 15 var builder = new Builder();
14 16
15 17 try{
@@ -21,15 +23,35 @@ namespace Gablabel
21 23 ButtonsType.CLOSE,
22 24 _("Cannot launch de preferences dialog: %s"), e.message);
23 25 messageDialog.run();
  26 + messageDialog.destroy();
24 27 return;
25 28 }
26 29
27 30 dialog = builder.get_object("preferences_dialog") as Dialog;
28   - settings = App().get_settings();
29   - }
30   -
31   - public void run(){
  31 + var settings = App().settings;
  32 +
  33 + var clipboardEntry = builder.get_object("entry_clipboard") as Entry;
  34 + var selectedEntry = builder.get_object("entry_selected") as Entry;
  35 +
  36 + settings.bind("clipboard-binding", clipboardEntry, "text", SettingsBindFlags.DEFAULT);
  37 + settings.bind("selected-binding", selectedEntry, "text", SettingsBindFlags.DEFAULT);
  38 +
  39 + /*clipboardEntry.text = settings.get_string("clipboard-binding");
  40 + selectedEntry.text = settings.get_string("selected-binding");
  41 +
  42 + clipboardEntry.focus_out_event.connect(() => {
  43 + stdout.printf("Se va a settear\n");
  44 + settings.set_string("clipboard-binding", clipboardEntry.text);
  45 + stdout.printf("Setteado\n");
  46 + return false;
  47 + });
  48 + selectedEntry.focus_out_event.connect((event) => {
  49 + settings.set_string("selected-binding", selectedEntry.text);
  50 + return false;
  51 + });*/
  52 +
32 53 dialog.run();
  54 + dialog.destroy();
33 55 }
34 56 }
35 57 }
1  src/TranslatorWebView.vala
@@ -55,7 +55,6 @@ namespace Gablabel
55 55 string finalText;
56 56 finalText = text.replace("\t", " ").escape("");
57 57 script = script.replace("@SOURCE_TEXT@", finalText);
58   - stdout.printf(script + "\n");
59 58 this.execute_script(script);
60 59 } catch(Error e){
61 60 }
2  vapi/config.vapi
@@ -12,4 +12,6 @@ namespace Config {
12 12 * passed to underlying C code as cmd line macros. */
13 13 public const string LOCALEDIR; /* /usr/local/share/locale */
14 14 public const string DATADIR; /* /usr/local/share/gablabel */
  15 +
  16 + public const int USE_GSETTINGS;
15 17 }

0 comments on commit a4b7b78

Please sign in to comment.
Something went wrong with that request. Please try again.