[quick-lounge-applet] set the launch context screen before launching
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Subject: [quick-lounge-applet] set the launch context screen before launching
- Date: Tue, 16 Jun 2009 03:50:43 -0400 (EDT)
commit 99467cbde4d1664ae54f50898b342b60814df209
Author: Paolo Bacchilega <paobac src gnome org>
Date: Tue Jun 16 09:48:28 2009 +0200
set the launch context screen before launching
src/file-utils.c | 307 +++++++++++++++++++++++++++---------------------------
1 files changed, 154 insertions(+), 153 deletions(-)
---
diff --git a/src/file-utils.c b/src/file-utils.c
index 227c62d..b65edc7 100644
--- a/src/file-utils.c
+++ b/src/file-utils.c
@@ -44,7 +44,7 @@ typedef struct {
} PathListData;
-void
+void
path_list_data_free (PathListData *pli)
{
g_object_unref (pli->directory);
@@ -54,10 +54,10 @@ path_list_data_free (PathListData *pli)
}
-void
+void
path_list_async_done (PathListData *pli)
{
- if (pli->done_func != NULL)
+ if (pli->done_func != NULL)
pli->done_func (pli->dirs, pli->files, pli->error, pli->done_data);
path_list_data_free (pli);
}
@@ -65,8 +65,8 @@ path_list_async_done (PathListData *pli)
static void
path_list_close_enumerator_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GFileEnumerator *enumerator = (GFileEnumerator *) source_object;
PathListData *pli = user_data;
@@ -94,8 +94,8 @@ path_list_files_ready_cb (GObject *source_object,
pli->error = NULL;
children = g_file_enumerator_next_files_finish (enumerator,
- result,
- &(pli->error));
+ result,
+ &(pli->error));
if (children == NULL) {
g_file_enumerator_close_async (enumerator,
@@ -109,11 +109,11 @@ path_list_files_ready_cb (GObject *source_object,
for (scan = children; scan; scan = scan->next) {
GFileInfo *info = scan->data;
GFile *file;
-
+
file = g_file_get_child (pli->directory, g_file_info_get_name (info));
if (file == NULL)
continue;
-
+
switch (g_file_info_get_file_type (info)) {
case G_FILE_TYPE_DIRECTORY:
pli->dirs = g_list_prepend (pli->dirs, g_file_get_uri (file));
@@ -124,16 +124,16 @@ path_list_files_ready_cb (GObject *source_object,
default:
break;
}
-
+
g_object_unref (file);
}
g_file_enumerator_next_files_async (enumerator,
- 128,
- G_PRIORITY_DEFAULT,
- pli->cancellable,
- path_list_files_ready_cb,
- pli);
+ 128,
+ G_PRIORITY_DEFAULT,
+ pli->cancellable,
+ path_list_files_ready_cb,
+ pli);
}
@@ -152,35 +152,35 @@ path_list_ready_cb (GObject *source_object,
}
g_file_enumerator_next_files_async (enumerator,
- 128,
- G_PRIORITY_DEFAULT,
- pli->cancellable,
- path_list_files_ready_cb,
- pli);
+ 128,
+ G_PRIORITY_DEFAULT,
+ pli->cancellable,
+ path_list_files_ready_cb,
+ pli);
}
void
-path_list_async_new (const gchar *uri,
+path_list_async_new (const gchar *uri,
GCancellable *cancellable,
PathListDoneFunc f,
gpointer data)
{
PathListData *pli;
-
+
pli = g_new0 (PathListData, 1);
pli->directory = g_file_new_for_uri (uri);
pli->cancellable = cancellable;
pli->done_func = f;
pli->done_data = data;
-
+
g_file_enumerate_children_async (pli->directory,
- "standard::*",
+ "standard::*",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
- pli->cancellable,
+ pli->cancellable,
path_list_ready_cb,
- pli);
+ pli);
}
@@ -244,54 +244,54 @@ path_is_dir (const char *path)
}
-gboolean
-file_copy (const char *source_uri,
+gboolean
+file_copy (const char *source_uri,
const char *destination_uri)
-{
+{
GFile *source;
GFile *destination;
gboolean result;
-
+
source = g_file_new_for_uri (source_uri);
destination = g_file_new_for_uri (destination_uri);
-
+
result = g_file_copy (source, destination, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
-
+
g_object_unref (source);
g_object_unref (destination);
-
+
return result;
}
-gboolean
-path_list_new (const char *uri,
- GList **files,
+gboolean
+path_list_new (const char *uri,
+ GList **files,
GList **dirs)
{
GFile *directory;
GFileEnumerator *enumerator;
GFileInfo *info;
-
+
directory = g_file_new_for_uri (uri);
- enumerator = g_file_enumerate_children (directory,
- "standard::*",
+ enumerator = g_file_enumerate_children (directory,
+ "standard::*",
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
-
+
if (enumerator == NULL) {
g_object_unref (directory);
return FALSE;
- }
-
+ }
+
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
GFile *file;
-
+
file = g_file_get_child (directory, g_file_info_get_name (info));
if (file == NULL)
continue;
-
+
switch (g_file_info_get_file_type (info)) {
case G_FILE_TYPE_DIRECTORY:
if (dirs != NULL)
@@ -304,17 +304,17 @@ path_list_new (const char *uri,
default:
break;
}
-
+
g_object_unref (file);
g_object_unref (info);
}
-
- if (dirs != NULL)
+
+ if (dirs != NULL)
*dirs = g_list_reverse (*dirs);
- if (files != NULL)
+ if (files != NULL)
*files = g_list_reverse (*files);
-
+
g_object_unref (enumerator);
g_object_unref (directory);
@@ -327,15 +327,15 @@ path_list_dup (GList *list)
{
GList *new_list = NULL;
GList *scan;
-
+
for (scan = list; scan; scan = scan->next)
new_list = g_list_prepend (new_list, g_strdup ((char *) scan->data));
-
+
return g_list_reverse (new_list);
}
-void
+void
path_list_free (GList *list)
{
if (list == NULL)
@@ -349,24 +349,24 @@ const char *
file_name_from_path (const char *file_name)
{
register gssize base;
- register gssize last_char;
+ register gssize last_char;
- if (file_name == NULL)
- return NULL;
+ if (file_name == NULL)
+ return NULL;
- if (file_name[0] == '\0')
- return "";
+ if (file_name[0] == '\0')
+ return "";
- last_char = strlen (file_name) - 1;
+ last_char = strlen (file_name) - 1;
- if (file_name [last_char] == G_DIR_SEPARATOR)
- return "";
+ if (file_name [last_char] == G_DIR_SEPARATOR)
+ return "";
- base = last_char;
- while ((base >= 0) && (file_name [base] != G_DIR_SEPARATOR))
- base--;
+ base = last_char;
+ while ((base >= 0) && (file_name [base] != G_DIR_SEPARATOR))
+ base--;
- return file_name + base + 1;
+ return file_name + base + 1;
}
@@ -435,8 +435,8 @@ make_directory_tree_from_uri (const char *uri,
gboolean
make_directory_tree_from_path (const char *path,
- mode_t mode,
- GError **error)
+ mode_t mode,
+ GError **error)
{
char *uri;
gboolean result;
@@ -453,7 +453,7 @@ char *
get_unique_desktop_file (const char *base_dir)
{
static int n = 0;
-
+
while (TRUE) {
char *path;
char *name;
@@ -475,28 +475,28 @@ GHashTable *static_strings = NULL;
const char *
get_static_string (const char *s)
{
- const char *result;
+ const char *result;
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- if (static_strings == NULL)
- static_strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ if (static_strings == NULL)
+ static_strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- if (! g_hash_table_lookup_extended (static_strings, s, (gpointer*) &result, NULL)) {
- result = g_strdup (s);
- g_hash_table_insert (static_strings,
- (gpointer) result,
- GINT_TO_POINTER (1));
- }
+ if (! g_hash_table_lookup_extended (static_strings, s, (gpointer*) &result, NULL)) {
+ result = g_strdup (s);
+ g_hash_table_insert (static_strings,
+ (gpointer) result,
+ GINT_TO_POINTER (1));
+ }
- return result;
+ return result;
}
const char*
get_file_mime_type (const char *uri,
- gboolean fast_file_type)
+ gboolean fast_file_type)
{
GFile *file;
GFileInfo *info;
@@ -528,63 +528,63 @@ gboolean
is_desktop_file (const char *uri)
{
const char *mime_type;
-
+
mime_type = get_file_mime_type (uri, FALSE);
if (mime_type == NULL)
return FALSE;
return ((strcmp (mime_type, "application/x-gnome-app-info") == 0)
- || (strcmp (mime_type, "application/x-desktop") == 0));
+ || (strcmp (mime_type, "application/x-desktop") == 0));
}
GList *
get_file_list_from_url_list (char *url_list)
{
- GList *list = NULL;
- int i;
- char *url_start, *url_end;
-
- i = 0;
- url_start = url_list;
- while (url_list[i] != '\0') {
- while ((url_list[i] != '\0')
- && (url_list[i] != '\r')
- && (url_list[i] != '\n')) i++;
-
- url_end = url_list + i;
- list = g_list_prepend (list, g_strndup (url_start, url_end - url_start));
-
- while ((url_list[i] != '\0')
- && ((url_list[i] == '\r')
- || (url_list[i] == '\n'))) i++;
- url_start = url_list + i;
- }
-
- return g_list_reverse (list);
+ GList *list = NULL;
+ int i;
+ char *url_start, *url_end;
+
+ i = 0;
+ url_start = url_list;
+ while (url_list[i] != '\0') {
+ while ((url_list[i] != '\0')
+ && (url_list[i] != '\r')
+ && (url_list[i] != '\n')) i++;
+
+ url_end = url_list + i;
+ list = g_list_prepend (list, g_strndup (url_start, url_end - url_start));
+
+ while ((url_list[i] != '\0')
+ && ((url_list[i] == '\r')
+ || (url_list[i] == '\n'))) i++;
+ url_start = url_list + i;
+ }
+
+ return g_list_reverse (list);
}
gboolean
g_write_file (GFile *file,
gboolean make_backup,
- GFileCreateFlags flags,
+ GFileCreateFlags flags,
void *buffer,
- gsize count,
+ gsize count,
GCancellable *cancellable,
GError **error)
{
gboolean success;
GOutputStream *stream;
-
+
stream = (GOutputStream *) g_file_replace (file, NULL, make_backup, flags, cancellable, error);
if (stream != NULL)
- success = g_output_stream_write_all (stream, buffer, count, NULL, cancellable, error);
+ success = g_output_stream_write_all (stream, buffer, count, NULL, cancellable, error);
else
success = FALSE;
-
+
g_object_unref (stream);
-
+
return success;
}
@@ -600,22 +600,22 @@ _g_key_file_cleanup (GKeyFile *file)
GKeyFile *
_g_key_file_dup (GKeyFile *file)
{
-
+
GKeyFile *new_file;
-
+
if (file != NULL) {
char *data;
gsize length;
-
- new_file = g_key_file_new ();
+
+ 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_key_file_load_from_data (new_file, data, length, G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
+
g_free (data);
}
- else
+ else
new_file = _g_desktop_entry_new (DESKTOP_ENTRY_TYPE_APPLICATION);
-
+
return new_file;
}
@@ -624,12 +624,12 @@ 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);
@@ -640,7 +640,7 @@ _g_desktop_entry_new (DesktopEntryType type)
default:
break;
}
-
+
return new_file;
}
@@ -652,59 +652,59 @@ _g_desktop_entry_new_for_uri (const char *uri)
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);
+ 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;
}
@@ -717,7 +717,7 @@ _g_desktop_entry_equal (GKeyFile *file1,
char *value1;
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) {
@@ -725,12 +725,12 @@ _g_desktop_entry_equal (GKeyFile *file1,
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)
+ terminal2 = g_key_file_get_boolean (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
+ if (terminal1 != terminal2)
return FALSE;
-
+
value1 = g_key_file_get_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
value2 = g_key_file_get_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
if (g_strcmp0 (value1, value2) != 0) {
@@ -738,7 +738,7 @@ _g_desktop_entry_equal (GKeyFile *file1,
g_free (value2);
return FALSE;
}
-
+
value1 = g_key_file_get_locale_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
value2 = g_key_file_get_locale_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
if (g_strcmp0 (value1, value2) != 0) {
@@ -754,7 +754,7 @@ _g_desktop_entry_equal (GKeyFile *file1,
g_free (value2);
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) {
@@ -762,7 +762,7 @@ _g_desktop_entry_equal (GKeyFile *file1,
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) {
@@ -770,8 +770,8 @@ _g_desktop_entry_equal (GKeyFile *file1,
g_free (value2);
return FALSE;
}
-
- return TRUE;
+
+ return TRUE;
}
@@ -782,9 +782,9 @@ _g_desktop_entry_launch (GKeyFile *desktop_entry,
{
GKeyFile *key_file;
char *type;
-
+
key_file = _g_key_file_dup (desktop_entry);
-
+
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;
@@ -796,26 +796,27 @@ _g_desktop_entry_launch (GKeyFile *desktop_entry,
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))
+ context = gdk_app_launch_context_new ();
+ gdk_app_launch_context_set_screen (context, gtk_widget_get_screen (source));
+ gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME);
+ 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]