quick-lounge-applet r265 - in trunk: . data/ui po src
- From: paobac svn gnome org
- To: svn-commits-list gnome org
- Subject: quick-lounge-applet r265 - in trunk: . data/ui po src
- Date: Tue, 10 Feb 2009 23:20:09 +0000 (UTC)
Author: paobac
Date: Tue Feb 10 23:20:09 2009
New Revision: 265
URL: http://svn.gnome.org/viewvc/quick-lounge-applet?rev=265&view=rev
Log:
2009-02-11 Paolo Bacchilega <paobac svn gnome org>
* src/quick-lounge.h:
* src/quick-lounge.c:
* src/quick-desktop-entry-dialog.c:
* src/quick-box.c:
* src/file-utils.h:
* src/file-utils.c:
* src/dlg-properties.c:
* data/ui/Makefile.am:
* data/ui/link-entry-editor.ui: new file
* data/ui/desktop-entry-editor.ui:
New feature: Allow to add links to files by dragging the
file on the preferences dialog.
New feature: Support URL launchers.
Added:
trunk/data/ui/link-entry-editor.ui
Modified:
trunk/ChangeLog
trunk/data/ui/Makefile.am
trunk/data/ui/desktop-entry-editor.ui
trunk/po/ChangeLog
trunk/po/POTFILES.in
trunk/src/dlg-properties.c
trunk/src/file-utils.c
trunk/src/file-utils.h
trunk/src/quick-box.c
trunk/src/quick-desktop-entry-dialog.c
trunk/src/quick-lounge.c
trunk/src/quick-lounge.h
Modified: trunk/data/ui/Makefile.am
==============================================================================
--- trunk/data/ui/Makefile.am (original)
+++ trunk/data/ui/Makefile.am Tue Feb 10 23:20:09 2009
@@ -1,7 +1,8 @@
uidir = $(datadir)/quick-lounge-applet/ui
ui_DATA = \
- add-from-menu.ui \
+ add-from-menu.ui \
desktop-entry-editor.ui \
+ link-entry-editor.ui \
properties.ui
EXTRA_DIST = $(ui_DATA)
Modified: trunk/data/ui/desktop-entry-editor.ui
==============================================================================
--- trunk/data/ui/desktop-entry-editor.ui (original)
+++ trunk/data/ui/desktop-entry-editor.ui Tue Feb 10 23:20:09 2009
@@ -38,7 +38,7 @@
<property name="visible">True</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
- <property name="column_spacing">6</property>
+ <property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkLabel" id="type_label">
@@ -48,9 +48,13 @@
<property name="use_markup">True</property>
<property name="use_underline">True</property>
</object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
</child>
<child>
- <object class="GtkLabel" id="label2">
+ <object class="GtkLabel" id="name_label">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog."><b>_Name:</b></property>
@@ -61,10 +65,12 @@
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkLabel" id="label3">
+ <object class="GtkLabel" id="exec_label">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog."><b>_Command:</b></property>
@@ -75,10 +81,12 @@
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkLabel" id="label4">
+ <object class="GtkLabel" id="comment_label">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog."><b>C_omment:</b></property>
@@ -89,6 +97,8 @@
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
@@ -102,6 +112,7 @@
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
@@ -115,12 +126,13 @@
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox1">
+ <object class="GtkHBox" id="exec_hbox">
<property name="visible">True</property>
- <property name="spacing">6</property>
+ <property name="spacing">12</property>
<child>
<object class="GtkEntry" id="exec_entry">
<property name="visible">True</property>
@@ -133,7 +145,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="browse_button">
+ <object class="GtkButton" id="exec_browse_button">
<property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog.">_Browse...</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -141,6 +153,7 @@
<property name="use_underline">True</property>
</object>
<packing>
+ <property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -150,6 +163,7 @@
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
@@ -162,6 +176,7 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
Added: trunk/data/ui/link-entry-editor.ui
==============================================================================
--- (empty file)
+++ trunk/data/ui/link-entry-editor.ui Tue Feb 10 23:20:09 2009
@@ -0,0 +1,158 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.14"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkHBox" id="desktop_entry_editor">
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkButton" id="icon_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <child>
+ <object class="GtkImage" id="icon_image">
+ <property name="visible">True</property>
+ <property name="stock">gtk-missing-image</property>
+ <property name="icon-size">6</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkTable" id="table1">
+ <property name="visible">True</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="name_label">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog."><b>_Name:</b></property>
+ <property name="use_markup">True</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">name_entry</property>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="comment_label">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog."><b>C_omment:</b></property>
+ <property name="use_markup">True</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">comment_entry</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="name_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="comment_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="url_label">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog."><b>_Location:</b></property>
+ <property name="use_markup">True</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">url_entry</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="url_hbox">
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkEntry" id="url_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="invisible_char_set">True</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="url_browse_button">
+ <property name="label" translatable="yes" comments="Use the same translation used by the GNOME Panel in the Launcher Properties dialog.">_Browse...</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+</interface>
Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in (original)
+++ trunk/po/POTFILES.in Tue Feb 10 23:20:09 2009
@@ -6,6 +6,7 @@
data/quick-lounge.schemas.in
[type: gettext/glade]data/ui/add-from-menu.ui
[type: gettext/glade]data/ui/desktop-entry-editor.ui
+[type: gettext/glade]data/ui/link-entry-editor.ui
[type: gettext/glade]data/ui/properties.ui
src/dlg-add-from-menu.c
src/dlg-add-from-menu.h
Modified: trunk/src/dlg-properties.c
==============================================================================
--- trunk/src/dlg-properties.c (original)
+++ trunk/src/dlg-properties.c Tue Feb 10 23:20:09 2009
@@ -755,8 +755,16 @@
GtkWidget *button;
int button_pos;
- if (! is_desktop_file (src_uri))
+ if (! is_desktop_file (src_uri)) {
+ GKeyFile *desktop_entry;
+
+ desktop_entry = _g_desktop_entry_new_for_uri (src_uri);
+ quick_lounge_add_launcher (quick_lounge, desktop_entry, pos);
+
+ g_key_file_free (desktop_entry);
+
continue;
+ }
uri = g_build_filename (quick_lounge->location,
file_name_from_path (src_uri),
Modified: trunk/src/file-utils.c
==============================================================================
--- trunk/src/file-utils.c (original)
+++ trunk/src/file-utils.c Tue Feb 10 23:20:09 2009
@@ -603,19 +603,108 @@
GKeyFile *new_file;
- new_file = g_key_file_new ();
if (file != NULL) {
char *data;
gsize length;
-
+
+ new_file = g_key_file_new ();
data = g_key_file_to_data (file, &length, NULL);
g_key_file_load_from_data (new_file, data, length, G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
g_free (data);
}
else
+ new_file = _g_desktop_entry_new (DESKTOP_ENTRY_TYPE_APPLICATION);
+
+ return new_file;
+}
+
+
+GKeyFile *
+_g_desktop_entry_new (DesktopEntryType type)
+{
+ GKeyFile *new_file;
+
+ new_file = g_key_file_new ();
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, "Encoding", "UTF-8");
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, "Version", "1.0");
+
+ switch (type) {
+ case DESKTOP_ENTRY_TYPE_APPLICATION:
g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
+ break;
+ case DESKTOP_ENTRY_TYPE_LINK:
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, G_KEY_FILE_DESKTOP_TYPE_LINK);
+ break;
+ default:
+ break;
+ }
+
+ return new_file;
+}
+
+
+GKeyFile *
+_g_desktop_entry_new_for_uri (const char *uri)
+{
+ GKeyFile *new_file;
+ GFile *file;
+ GFileInfo *info;
+ char *comment;
+
+ new_file = _g_desktop_entry_new (DESKTOP_ENTRY_TYPE_LINK);
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, uri);
+
+ file = g_file_new_for_uri (uri);
+ info = g_file_query_info (file, "standard::icon,standard::display-name", 0, NULL, NULL);
+ if (info != NULL) {
+ GIcon *icon;
+ char *icon_name;
+
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, g_file_info_get_display_name (info));
+
+ icon = g_file_info_get_icon (info);
+ if (G_IS_THEMED_ICON (icon)) {
+ GtkIconTheme *icon_theme;
+ char **names;
+ int i;
+
+ icon_theme = gtk_icon_theme_get_default ();
+ g_object_get (G_OBJECT (icon), "names", &names, NULL);
+ for (i = 0; names[i] != NULL; i++) {
+ if (gtk_icon_theme_has_icon (icon_theme, names[i])) {
+ icon_name = g_strdup (names[i]);
+ break;
+ }
+ }
+
+ g_strfreev (names);
+ }
+ else if (G_IS_FILE_ICON (icon)) {
+ GFile *file;
+
+ file = g_file_icon_get_file (G_FILE_ICON (icon));
+ icon_name = g_file_get_path (file);
+ g_object_unref (file);
+ }
+ else
+ icon_name = NULL;
+ if (icon_name != NULL)
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, icon_name);
+
+ g_free (icon_name);
+ g_object_unref (info);
+ }
+ g_object_unref (file);
+
+ /* Translators: %s is a URI */
+ comment = g_strdup_printf ("Open '%s'", uri);
+ g_key_file_set_string (new_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, comment);
+
+ g_free (comment);
+
return new_file;
}
@@ -629,6 +718,14 @@
gboolean terminal2;
char *value2;
+ value1 = g_key_file_get_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
+ value2 = g_key_file_get_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
+ if (g_strcmp0 (value1, value2) != 0) {
+ g_free (value1);
+ g_free (value2);
+ return FALSE;
+ }
+
terminal1 = g_key_file_get_boolean (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
terminal2 = g_key_file_get_boolean (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
if (terminal1 != terminal2)
@@ -658,6 +755,14 @@
return FALSE;
}
+ value1 = g_key_file_get_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, NULL);
+ value2 = g_key_file_get_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, NULL);
+ if (g_strcmp0 (value1, value2) != 0) {
+ g_free (value1);
+ g_free (value2);
+ return FALSE;
+ }
+
value1 = g_key_file_get_locale_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
value2 = g_key_file_get_locale_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
if (g_strcmp0 (value1, value2) != 0) {
@@ -675,25 +780,42 @@
GtkWidget *source,
GList *files)
{
- GKeyFile *key_file;
- char *path;
- GDesktopAppInfo *app_info;
- GdkAppLaunchContext *context;
- GError *error = NULL;
+ GKeyFile *key_file;
+ char *type;
key_file = _g_key_file_dup (desktop_entry);
- path = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_PATH, NULL);
- if (path == NULL)
- g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_PATH, g_get_home_dir ());
- g_free (path);
-
- app_info = g_desktop_app_info_new_from_keyfile (key_file);
- context = gdk_app_launch_context_new ();
-
- if (! g_app_info_launch_uris (G_APP_INFO (app_info), files, G_APP_LAUNCH_CONTEXT (context), &error))
- _gtk_error_dialog_from_gerror_run (NULL, _("Could not launch the application"), &error);
-
- g_object_unref (context);
- g_object_unref (app_info);
+
+ type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
+ if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) == 0) {
+ char *path;
+ GDesktopAppInfo *app_info;
+ GdkAppLaunchContext *context;
+ GError *error = NULL;
+
+ path = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_PATH, NULL);
+ if (path == NULL)
+ g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_PATH, g_get_home_dir ());
+ g_free (path);
+
+ app_info = g_desktop_app_info_new_from_keyfile (key_file);
+ context = gdk_app_launch_context_new ();
+
+ if (! g_app_info_launch_uris (G_APP_INFO (app_info), files, G_APP_LAUNCH_CONTEXT (context), &error))
+ _gtk_error_dialog_from_gerror_run (NULL, _("Could not launch the application"), &error);
+
+ g_object_unref (context);
+ g_object_unref (app_info);
+ }
+ else if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_LINK) == 0) {
+ char *url;
+ GError *error = NULL;
+
+ url = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, NULL);
+ if (! gtk_show_uri ((source != NULL ? gtk_widget_get_screen (source) : NULL), url, 0, &error))
+ _gtk_error_dialog_from_gerror_run (NULL, _("Could not show the location"), &error);
+
+ g_free (url);
+ }
+
g_key_file_free (key_file);
}
Modified: trunk/src/file-utils.h
==============================================================================
--- trunk/src/file-utils.h (original)
+++ trunk/src/file-utils.h Tue Feb 10 23:20:09 2009
@@ -31,8 +31,16 @@
#include "typedefs.h"
+typedef enum {
+ DESKTOP_ENTRY_TYPE_UNKNOWN,
+ DESKTOP_ENTRY_TYPE_APPLICATION,
+ DESKTOP_ENTRY_TYPE_LINK
+} DesktopEntryType;
+
+
typedef void (*PathListDoneFunc) (GList *files, GList *dirs, GError *error, gpointer data);
+
gboolean uri_is_file (const char *uri);
gboolean uri_is_dir (const char *uri);
gboolean path_is_dir (const char *path);
@@ -67,8 +75,10 @@
gsize count,
GCancellable *cancellable,
GError **error);
-GKeyFile * _g_key_file_dup (GKeyFile *file);
void _g_key_file_cleanup (GKeyFile *file);
+GKeyFile * _g_key_file_dup (GKeyFile *file);
+GKeyFile * _g_desktop_entry_new (DesktopEntryType type);
+GKeyFile * _g_desktop_entry_new_for_uri (const char *uri);
gboolean _g_desktop_entry_equal (GKeyFile *file1,
GKeyFile *file2);
void _g_desktop_entry_launch (GKeyFile *desktop_entry,
Modified: trunk/src/quick-box.c
==============================================================================
--- trunk/src/quick-box.c (original)
+++ trunk/src/quick-box.c Tue Feb 10 23:20:09 2009
@@ -1424,7 +1424,9 @@
if ((x >= rect.x) && (x <= rect.x + rect.width)
&& (y >= rect.y) && (y <= rect.y + rect.height))
+ {
return pos;
+ }
if ((x >= rect.x) && (x <= rect.x + rect.width))
same_col_pos = pos;
Modified: trunk/src/quick-desktop-entry-dialog.c
==============================================================================
--- trunk/src/quick-desktop-entry-dialog.c (original)
+++ trunk/src/quick-desktop-entry-dialog.c Tue Feb 10 23:20:09 2009
@@ -40,10 +40,11 @@
struct _QuickDesktopEntryDialogPrivate {
- GtkBuilder *builder;
- GtkWidget *type_combobox;
- GKeyFile *original;
- GKeyFile *current;
+ GtkBuilder *builder;
+ GtkWidget *type_combobox;
+ DesktopEntryType entry_type;
+ GKeyFile *original;
+ GKeyFile *current;
};
@@ -136,7 +137,7 @@
{
g_key_file_set_boolean (self->priv->current,
G_KEY_FILE_DESKTOP_GROUP,
- G_KEY_FILE_DESKTOP_KEY_NAME,
+ G_KEY_FILE_DESKTOP_KEY_TERMINAL,
gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->type_combobox)) == 1);
quick_desktop_entry_dialog_changed (self);
}
@@ -172,6 +173,18 @@
static void
+url_entry_changed_cb (GtkEditable *editable,
+ QuickDesktopEntryDialog *self)
+{
+ g_key_file_set_string (self->priv->current,
+ G_KEY_FILE_DESKTOP_GROUP,
+ G_KEY_FILE_DESKTOP_KEY_URL,
+ gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("url_entry"))));
+ quick_desktop_entry_dialog_changed (self);
+}
+
+
+static void
comment_entry_changed_cb (GtkEditable *editable,
QuickDesktopEntryDialog *self)
{
@@ -293,7 +306,7 @@
QuickDesktopEntryDialog *self)
{
GtkFileChooser *file_chooser = GTK_FILE_CHOOSER (widget);
- char *command;
+ gboolean changed = FALSE;
if ((response == GTK_RESPONSE_CANCEL) || (response == GTK_RESPONSE_DELETE_EVENT)) {
gtk_widget_destroy (widget);
@@ -302,18 +315,33 @@
if (response != GTK_RESPONSE_OK)
return;
+
+ if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_APPLICATION) {
+ char *command;
+
+ command = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser));
+ if (command != NULL) {
+ g_key_file_set_string (self->priv->current, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, command);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("exec_entry")), command);
+ changed = TRUE;
+ }
+ }
+ else if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_LINK) {
+ char *uri;
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_chooser));
+ if (uri != NULL) {
+ g_key_file_set_string (self->priv->current, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, uri);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("url_entry")), uri);
+ changed = TRUE;
+ }
+ }
- command = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser));
- if (command == NULL)
- return;
-
- g_key_file_set_string (self->priv->current, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, command);
- gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("exec_entry")), command);
-
+ if (! changed)
+ return;
+
quick_desktop_entry_dialog_changed (self);
gtk_widget_destroy (GTK_WIDGET (file_chooser));
-
- g_free (command);
}
@@ -327,7 +355,7 @@
char *uri;
gboolean set_current = FALSE;
- command_chooser = gtk_file_chooser_dialog_new (_("Select a Command"),
+ command_chooser = gtk_file_chooser_dialog_new ((self->priv->entry_type == DESKTOP_ENTRY_TYPE_APPLICATION) ? _("Select a Command") : _("Select a File"),
GTK_WINDOW (self),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
@@ -338,7 +366,13 @@
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (command_chooser),TRUE);
gtk_dialog_set_default_response (GTK_DIALOG (command_chooser), GTK_RESPONSE_OK);
- path = g_key_file_get_string (self->priv->current, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_APPLICATION)
+ path = g_key_file_get_string (self->priv->current, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ else if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_LINK)
+ path = g_key_file_get_string (self->priv->current, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, NULL);
+ else
+ path = NULL;
+
if ((path == NULL) || (path[0] != '/')) {
g_free (path);
path = g_strdup (g_get_home_dir ());
@@ -371,56 +405,16 @@
GtkWindow *parent,
GKeyFile *entry)
{
- GtkWidget *content;
-
if (title != NULL)
gtk_window_set_title (GTK_WINDOW (self), title);
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (self), parent);
- gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
+ gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (self)->vbox), 5);
gtk_container_set_border_width (GTK_CONTAINER (self), 5);
- self->priv->builder = _gtk_builder_new_from_file ("desktop-entry-editor.ui");
-
- content = _gtk_builder_get_widget (self->priv->builder, "desktop_entry_editor");
- gtk_container_set_border_width (GTK_CONTAINER (content), 5);
- gtk_widget_show (content);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (self)->vbox), content, TRUE, TRUE, 0);
-
- self->priv->type_combobox = _gtk_combo_box_new_with_texts (_("Application"), _("Application in Terminal"), NULL);
- gtk_widget_show (self->priv->type_combobox);
- gtk_box_pack_start (GTK_BOX (GET_WIDGET ("type_box")), self->priv->type_combobox, TRUE, TRUE, 0);
-
- gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("type_label")), self->priv->type_combobox);
-
- quick_desktop_entry_dialog_set_entry (self, entry);
-
- g_signal_connect (self->priv->type_combobox,
- "changed",
- G_CALLBACK (type_combobox_changed_cb),
- self);
- g_signal_connect (GET_WIDGET ("name_entry"),
- "changed",
- G_CALLBACK (name_entry_changed_cb),
- self);
- g_signal_connect (GET_WIDGET ("exec_entry"),
- "changed",
- G_CALLBACK (exec_entry_changed_cb),
- self);
- g_signal_connect (GET_WIDGET ("comment_entry"),
- "changed",
- G_CALLBACK (comment_entry_changed_cb),
- self);
- g_signal_connect (GET_WIDGET ("icon_button"),
- "clicked",
- G_CALLBACK (icon_button_clicked_cb),
- self);
- g_signal_connect (GET_WIDGET ("browse_button"),
- "clicked",
- G_CALLBACK (browse_button_clicked_cb),
- self);
+ quick_desktop_entry_dialog_set_entry (self, entry);
}
@@ -442,23 +436,39 @@
quick_desktop_entry_dialog_update (QuickDesktopEntryDialog *self,
GKeyFile *entry)
{
- gboolean terminal;
- char *name;
- char *exec;
- char *comment;
- terminal = g_key_file_get_boolean (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
- name = g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
- exec = g_key_file_get_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
- comment = g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
- gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->type_combobox), terminal ? 1 : 0);
+ char *name;
+ char *comment;
+
+ if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_APPLICATION) {
+ gboolean terminal;
+ char *exec;
+
+ terminal = g_key_file_get_boolean (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->type_combobox), terminal ? 1 : 0);
+
+ exec = g_key_file_get_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("exec_entry")), exec ? exec : "");
+
+ g_free (exec);
+ }
+ else if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_LINK) {
+ char *url;
+
+ url = g_key_file_get_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, NULL);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("url_entry")), url ? url : "");
+
+ g_free (url);
+ }
+
+ name = g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), name ? name : "");
- gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("exec_entry")), exec ? exec : "");
+
+ comment = g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("comment_entry")), comment ? comment : "");
g_free (comment);
- g_free (exec);
g_free (name);
quick_desktop_entry_dialog_update_icon (self, entry);
@@ -469,6 +479,9 @@
quick_desktop_entry_dialog_set_entry (QuickDesktopEntryDialog *self,
GKeyFile *entry)
{
+ char *type;
+ GtkWidget *content;
+
if (self->priv->original != NULL)
g_key_file_free (self->priv->original);
self->priv->original = _g_key_file_dup (entry);
@@ -476,8 +489,82 @@
if (self->priv->current != NULL)
g_key_file_free (self->priv->current);
self->priv->current = _g_key_file_dup (entry);
+
+ /**/
+
+ type = g_key_file_get_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
+ if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) == 0)
+ self->priv->entry_type = DESKTOP_ENTRY_TYPE_APPLICATION;
+ else if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_LINK) == 0)
+ self->priv->entry_type = DESKTOP_ENTRY_TYPE_LINK;
+ else
+ self->priv->entry_type = DESKTOP_ENTRY_TYPE_UNKNOWN;
+
+ if (self->priv->builder != NULL) {
+ g_object_unref (self->priv->builder);
+ self->priv->builder = NULL;
+ }
+
+ if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_UNKNOWN)
+ return;
+
+ if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_APPLICATION) {
+ self->priv->builder = _gtk_builder_new_from_file ("desktop-entry-editor.ui");
+
+ self->priv->type_combobox = _gtk_combo_box_new_with_texts (_("Application"), _("Application in Terminal"), NULL);
+ gtk_widget_show (self->priv->type_combobox);
+ gtk_box_pack_start (GTK_BOX (GET_WIDGET ("type_box")), self->priv->type_combobox, TRUE, TRUE, 0);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("type_label")), self->priv->type_combobox);
+ }
+ else if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_LINK)
+ self->priv->builder = _gtk_builder_new_from_file ("link-entry-editor.ui");
+
+ content = _gtk_builder_get_widget (self->priv->builder, "desktop_entry_editor");
+ gtk_container_set_border_width (GTK_CONTAINER (content), 5);
+ gtk_widget_show (content);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (self)->vbox), content, TRUE, TRUE, 0);
quick_desktop_entry_dialog_update (self, self->priv->current);
+
+ if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_APPLICATION) {
+ g_signal_connect (self->priv->type_combobox,
+ "changed",
+ G_CALLBACK (type_combobox_changed_cb),
+ self);
+ g_signal_connect (GET_WIDGET ("exec_entry"),
+ "changed",
+ G_CALLBACK (exec_entry_changed_cb),
+ self);
+ g_signal_connect (GET_WIDGET ("exec_browse_button"),
+ "clicked",
+ G_CALLBACK (browse_button_clicked_cb),
+ self);
+ }
+ else if (self->priv->entry_type == DESKTOP_ENTRY_TYPE_LINK) {
+ g_signal_connect (GET_WIDGET ("url_entry"),
+ "changed",
+ G_CALLBACK (url_entry_changed_cb),
+ self);
+ g_signal_connect (GET_WIDGET ("url_browse_button"),
+ "clicked",
+ G_CALLBACK (browse_button_clicked_cb),
+ self);
+ }
+
+ g_signal_connect (GET_WIDGET ("name_entry"),
+ "changed",
+ G_CALLBACK (name_entry_changed_cb),
+ self);
+ g_signal_connect (GET_WIDGET ("comment_entry"),
+ "changed",
+ G_CALLBACK (comment_entry_changed_cb),
+ self);
+ g_signal_connect (GET_WIDGET ("icon_button"),
+ "clicked",
+ G_CALLBACK (icon_button_clicked_cb),
+ self);
+
+ g_free (type);
}
Modified: trunk/src/quick-lounge.c
==============================================================================
--- trunk/src/quick-lounge.c (original)
+++ trunk/src/quick-lounge.c Tue Feb 10 23:20:09 2009
@@ -478,6 +478,57 @@
/* -- */
+gboolean
+quick_lounge_add_launcher (QuickLounge *quick_lounge,
+ GKeyFile *desktop_entry,
+ int position)
+{
+ gboolean launcher_added = FALSE;
+ GError *error = NULL;
+ char *data;
+ gsize length;
+ char *uri;
+ GFile *file;
+
+ if (desktop_entry == NULL)
+ return FALSE;
+
+ data = g_key_file_to_data (desktop_entry, &length, &error);
+ if (data == NULL) {
+ g_key_file_free (desktop_entry);
+ _gtk_error_dialog_run (NULL,
+ ERROR_FORMAT,
+ _("Could not create the new launcher"),
+ error->message);
+ g_clear_error (&error);
+ return FALSE;
+ }
+
+ uri = quick_lounge_util__get_unique_uri (quick_lounge);
+ file = g_file_new_for_uri (uri);
+ if (! g_write_file (file, FALSE, G_FILE_CREATE_NONE, data, length, NULL, &error)) {
+ _gtk_error_dialog_run (NULL,
+ ERROR_FORMAT,
+ _("Could not create the new launcher"),
+ error->message);
+ g_clear_error (&error);
+ }
+ else {
+ quick_box_add_button (quick_lounge->quick_box, uri, position);
+ quick_lounge_save_order (quick_lounge);
+ dlg_properties_update (quick_lounge->prop_dialog);
+
+ launcher_added = TRUE;
+ }
+
+ g_object_unref (file);
+ g_free (uri);
+ g_free (data);
+
+ return launcher_added;
+}
+
+
static void
new_desktop_entry_dialog_response_cb (GtkDialog *dialog,
int response,
@@ -486,10 +537,6 @@
EditItemData *edit_data = user_data;
GKeyFile *desktop_entry;
GError *error = NULL;
- char *data;
- gsize length;
- char *uri;
- GFile *file;
switch (response) {
case GTK_RESPONSE_HELP:
@@ -517,40 +564,9 @@
return;
}
- if (desktop_entry == NULL)
- return;
-
- data = g_key_file_to_data (desktop_entry, &length, &error);
- if (data == NULL) {
- g_key_file_free (desktop_entry);
- _gtk_error_dialog_run (NULL,
- ERROR_FORMAT,
- _("Could not create the new launcher"),
- error->message);
- g_clear_error (&error);
- return;
- }
-
- uri = quick_lounge_util__get_unique_uri (edit_data->quick_lounge);
- file = g_file_new_for_uri (uri);
- if (! g_write_file (file, FALSE, G_FILE_CREATE_NONE, data, length, NULL, &error)) {
- _gtk_error_dialog_run (NULL,
- ERROR_FORMAT,
- _("Could not create the new launcher"),
- error->message);
- g_clear_error (&error);
- }
- else {
- quick_box_add_button (edit_data->quick_lounge->quick_box, uri, edit_data->position + 1);
- quick_lounge_save_order (edit_data->quick_lounge);
- dlg_properties_update (edit_data->quick_lounge->prop_dialog);
-
+ if (quick_lounge_add_launcher (edit_data->quick_lounge, desktop_entry, edit_data->position + 1))
gtk_widget_destroy (GTK_WIDGET (dialog));
- }
- g_object_unref (file);
- g_free (uri);
- g_free (data);
g_key_file_free (desktop_entry);
}
Modified: trunk/src/quick-lounge.h
==============================================================================
--- trunk/src/quick-lounge.h (original)
+++ trunk/src/quick-lounge.h Tue Feb 10 23:20:09 2009
@@ -53,7 +53,10 @@
int value);
void quick_lounge_new_launcher (QuickLounge *quick_lounge,
int pos);
-
+gboolean quick_lounge_add_launcher (QuickLounge *quick_lounge,
+ GKeyFile *desktop_entry,
+ int pos);
+
/* utils */
void quick_lounge_util__item_properties (QuickLounge *quick_lounge,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]