Permalink
Browse files

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

…created.
  • Loading branch information...
1 parent 036e320 commit a4b7b783ad17032c0988b75aaf409f89c8b40db0 @dnohales committed Jan 18, 2012
View
6 CMakeLists.txt
@@ -20,4 +20,10 @@ include(ValaVersion)
find_package(Vala)
ensure_vala_version("0.11.0" MINIMUM)
+if(NOT DEFINED USE_GSETTINGS)
+ set(USE_GSETTINGS 1)
+endif()
+
add_subdirectory(src)
+
+unset(USE_GSETTINGS)
View
1 config.h.in
@@ -4,3 +4,4 @@
#define GETTEXT_PACKAGE "@GETTEXT_PACKAGE@"
#define LOCALEDIR "@LOCALEDIR@"
#define DATADIR "@DATADIR@"
+#define USE_GSETTINGS @USE_GSETTINGS@
View
12 data/es.nohal.Gablabel.gschema.xml
@@ -0,0 +1,12 @@
+<schemalist>
+ <schema id="es.nohal.Gablabel" path="/apps/gablabel/">
+ <key name="clipboard-binding" type="s">
+ <default>"&lt;Ctrl&gt;&lt;Alt&gt;W"</default>
+ <summary>Key binding for translate clipboard text</summary>
+ </key>
+ <key name="selected-binding" type="s">
+ <default>"&lt;Ctrl&gt;&lt;Alt&gt;S"</default>
+ <summary>Key binding for translate selected text</summary>
+ </key>
+ </schema>
+</schemalist>
View
3 data/gablabel/mainwindow.ui
@@ -68,6 +68,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
@@ -102,7 +103,7 @@ translator does not work well</property>
</packing>
</child>
<child>
- <object class="GtkToolButton" id="toolbutton_about">
+ <object class="GtkToolButton" id="toolbutton_preferences">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
View
10 data/gablabel/preferencesdialog.ui
@@ -6,6 +6,7 @@
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Gablabel preferences</property>
+ <property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
@@ -57,7 +58,7 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="entry1">
+ <object class="GtkEntry" id="entry_clipboard">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
@@ -73,7 +74,7 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="entry2">
+ <object class="GtkEntry" id="entry_selected">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
@@ -111,7 +112,6 @@
</child>
<child>
<object class="GtkAlignment" id="alignment2">
- <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">10</property>
<property name="left_padding">5</property>
@@ -187,7 +187,7 @@
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="button1">
+ <object class="GtkButton" id="button_close">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -211,7 +211,7 @@
</object>
</child>
<action-widgets>
- <action-widget response="0">button1</action-widget>
+ <action-widget response="0">button_close</action-widget>
</action-widgets>
</object>
</interface>
View
59 src/Application.vala
@@ -8,18 +8,15 @@ namespace Gablabel
return Application.singleton_instance;
}
- enum BindingName {
- CLIPBOARD,
- SELECTED
- }
-
public MainWindow window { get; private set; }
public StatusIconManager statusIcon { get; private set; }
public KeyBindingManager keyBindings { get; private set; }
public GLib.Settings settings { get; private set; }
- private Gee.Map<Application.BindingName, string> currentBindings = new Gee.HashMap<Application.BindingName, string>();
+ private Gee.Map<string, string> currentBindings = new Gee.HashMap<string, string>();
private Application(string[] args){
+ Application.singleton_instance = this;
+
Gtk.init(ref args);
Intl.bindtextdomain( Config.GETTEXT_PACKAGE, Config.LOCALEDIR );
@@ -29,19 +26,21 @@ namespace Gablabel
public int run(){
try{
+ keyBindings = new KeyBindingManager();
+
+ if(Config.USE_GSETTINGS == 1){
+ settings = new GLib.Settings("es.nohal.Gablabel");
+ on_settings_changed("clipboard-binding");
+ on_settings_changed("selected-binding");
+ settings.changed.connect(on_settings_changed);
+ }
+
window = new Gablabel.MainWindow();
statusIcon = new StatusIconManager(window);
+
window.start();
statusIcon.start();
- keyBindings = new KeyBindingManager();
- keyBindings.bind("<Ctrl><Alt>S", (event) => {
- statusIcon.on_selected_activated();
- });
-
- settings = new GLib.Settings("es.nohal.gablabel");
- settings.changed
-
Gtk.main();
return 0;
} catch(Error e){
@@ -50,8 +49,36 @@ namespace Gablabel
}
}
- private void refreshBindings(){
-
+ private KeyBindingManager.KeybindingHandlerFunc? handler_func_by_setting(string key)
+ {
+ switch(key)
+ {
+ case "clipboard-binding":
+ return () => {
+ statusIcon.on_clipboard_activated();
+ };
+ case "selected-binding":
+ return () => {
+ statusIcon.on_selected_activated();
+ };
+ default:
+ return null;
+ }
+ }
+
+ private void on_settings_changed(string key)
+ {
+ switch(key)
+ {
+ case "clipboard-binding":
+ case "selected-binding":
+ if(currentBindings.has_key(key)){
+ keyBindings.unbind(currentBindings[key]);
+ }
+ currentBindings[key] = settings.get_string(key);
+ keyBindings.bind(currentBindings[key], handler_func_by_setting(key));
+ break;
+ }
}
public static int main(string[] args){
View
4 src/MainWindow.vala
@@ -27,8 +27,6 @@ namespace Gablabel
mainMenu = builder.get_object("main_menu") as Menu;
buttonReload = builder.get_object("toolbutton_reload") as ToolButton;
menuItemReload = builder.get_object("main_menu_reload") as ImageMenuItem;
- AccelMap.add_entry("<Gablabel>/Clipboard", Gdk.keyval_from_name("r"), Gdk.ModifierType.CONTROL_MASK);
- menuItemReload.set_accel_path("<Gablabel>/Clipboard");
//Signals connection
this.delete_event.connect(this.hide_on_delete);
@@ -41,6 +39,7 @@ namespace Gablabel
buttonMainMenu.set_menu(mainMenu);
buttonMainMenu.clicked.connect(() => { buttonMainMenu.show_menu(); });
buttonReload.clicked.connect(webView.load_translator);
+ (builder.get_object("toolbutton_preferences") as ToolButton).clicked.connect(show_preferences_dialog);
(builder.get_object("main_menu_fullscreen") as ImageMenuItem).activate.connect(() => {
if(this.isFullscreen){
@@ -97,6 +96,7 @@ namespace Gablabel
dialog.authors = authors;
dialog.run();
+ dialog.destroy();
}
public void show_preferences_dialog(){
View
32 src/PreferencesDialogManager.vala
@@ -4,12 +4,14 @@ namespace Gablabel
{
public class PreferencesDialogManager
{
- private GLib.Settings settings;
private Dialog dialog;
private MainWindow parent;
public PreferencesDialogManager(MainWindow parent){
this.parent = parent;
+ }
+
+ public void run(){
var builder = new Builder();
try{
@@ -21,15 +23,35 @@ namespace Gablabel
ButtonsType.CLOSE,
_("Cannot launch de preferences dialog: %s"), e.message);
messageDialog.run();
+ messageDialog.destroy();
return;
}
dialog = builder.get_object("preferences_dialog") as Dialog;
- settings = App().get_settings();
- }
-
- public void run(){
+ var settings = App().settings;
+
+ var clipboardEntry = builder.get_object("entry_clipboard") as Entry;
+ var selectedEntry = builder.get_object("entry_selected") as Entry;
+
+ settings.bind("clipboard-binding", clipboardEntry, "text", SettingsBindFlags.DEFAULT);
+ settings.bind("selected-binding", selectedEntry, "text", SettingsBindFlags.DEFAULT);
+
+ /*clipboardEntry.text = settings.get_string("clipboard-binding");
+ selectedEntry.text = settings.get_string("selected-binding");
+
+ clipboardEntry.focus_out_event.connect(() => {
+ stdout.printf("Se va a settear\n");
+ settings.set_string("clipboard-binding", clipboardEntry.text);
+ stdout.printf("Setteado\n");
+ return false;
+ });
+ selectedEntry.focus_out_event.connect((event) => {
+ settings.set_string("selected-binding", selectedEntry.text);
+ return false;
+ });*/
+
dialog.run();
+ dialog.destroy();
}
}
}
View
1 src/TranslatorWebView.vala
@@ -55,7 +55,6 @@ namespace Gablabel
string finalText;
finalText = text.replace("\t", " ").escape("");
script = script.replace("@SOURCE_TEXT@", finalText);
- stdout.printf(script + "\n");
this.execute_script(script);
} catch(Error e){
}
View
2 vapi/config.vapi
@@ -12,4 +12,6 @@ namespace Config {
* passed to underlying C code as cmd line macros. */
public const string LOCALEDIR; /* /usr/local/share/locale */
public const string DATADIR; /* /usr/local/share/gablabel */
+
+ public const int USE_GSETTINGS;
}

0 comments on commit a4b7b78

Please sign in to comment.