~ubuntu-branches/debian/sid/gnome-main-menu/sid

« back to all changes in this revision

Viewing changes to libslab/app-shell-startup.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2009-11-08 21:22:49 UTC
  • mto: (5.1.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20091108212249-9cql8cptajeua2eh
Tags: upstream-0.9.13
ImportĀ upstreamĀ versionĀ 0.9.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of libslab.
3
 
 *
4
 
 * Copyright (c) 2006 Novell, Inc.
5
 
 *
6
 
 * Libslab is free software; you can redistribute it and/or modify it under the
7
 
 * terms of the GNU Lesser General Public License as published by the Free
8
 
 * Software Foundation; either version 2 of the License, or (at your option)
9
 
 * any later version.
10
 
 *
11
 
 * Libslab is distributed in the hope that it will be useful, but WITHOUT ANY
12
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
14
 
 * more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public License
17
 
 * along with libslab; if not, write to the Free Software Foundation, Inc., 51
18
 
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include <gtk/gtk.h>
22
 
#include <gdk/gdkx.h>
23
 
#include <libgnome/gnome-desktop-item.h>
24
 
 
25
 
#include "app-shell-startup.h"
26
 
#include "app-shell.h"
27
 
#include "search-bar.h"
28
 
#include "slab-section.h"
29
 
 
30
 
gint
31
 
apss_new_instance_cb (BonoboApplication * app, gint argc, char *argv[], gpointer data)
32
 
{
33
 
        AppShellData *app_data = (AppShellData *) data;
34
 
        SlabSection *section = SLAB_SECTION (app_data->filter_section);
35
 
        NldSearchBar *search_bar;
36
 
        gboolean visible;
37
 
 
38
 
        /* g_message ("new_instance_cb got called\n"); */
39
 
 
40
 
        /* Make sure our implementation has not changed */
41
 
        g_assert (NLD_IS_SEARCH_BAR (section->contents));
42
 
        search_bar = NLD_SEARCH_BAR (section->contents);
43
 
 
44
 
        g_object_get (app_data->main_gnome_app, "visible", &visible, NULL);
45
 
        if (!visible)
46
 
        {
47
 
                show_shell (app_data);
48
 
        }
49
 
 
50
 
        if (argc)               /* if we are passed a valid startup time */
51
 
        {
52
 
                gchar **results = g_strsplit (argv[0], "_TIME", 0);
53
 
                gint lastentry = 0;
54
 
                guint32 timestamp;
55
 
 
56
 
                while (results[lastentry] != NULL)
57
 
                        lastentry++;
58
 
                timestamp = (guint32) g_strtod (results[lastentry - 1], NULL);
59
 
                g_strfreev (results);
60
 
 
61
 
                /* gdk_x11_window_move_to_current_desktop(window);  */
62
 
                gdk_x11_window_set_user_time (app_data->main_gnome_app->window, timestamp);
63
 
        }
64
 
 
65
 
        gtk_window_present (GTK_WINDOW (app_data->main_gnome_app));
66
 
        gtk_widget_grab_focus (GTK_WIDGET (search_bar));
67
 
 
68
 
        return argc;
69
 
}
70
 
 
71
 
gboolean
72
 
apss_already_running (int argc, char *argv[], BonoboApplication ** app,
73
 
        const gchar * name, gchar * startup_id)
74
 
{
75
 
        gchar const *envp[] = { "LANG", NULL };
76
 
        char * display_name;
77
 
        gchar *serverinfo;
78
 
        BonoboAppClient *client;
79
 
        Bonobo_RegistrationResult reg_res;
80
 
 
81
 
        if (bonobo_init (&argc, argv) == FALSE)
82
 
                g_error ("Problem with bonobo_init");
83
 
        if (!bonobo_activate ())
84
 
                g_error ("Problem with bonobo_activate()");
85
 
 
86
 
        display_name = (char *) gdk_display_get_name (gdk_display_get_default ());
87
 
        bonobo_activation_set_activation_env_value ("DISPLAY", display_name);
88
 
 
89
 
        //make this a singleton per display per user
90
 
        display_name = g_strconcat (name, display_name, NULL);
91
 
        *app = bonobo_application_new (display_name);
92
 
        g_free (display_name);
93
 
 
94
 
        serverinfo = bonobo_application_create_serverinfo (*app, envp);
95
 
        reg_res = bonobo_application_register_unique (*app, serverinfo, &client);
96
 
        g_free (serverinfo);
97
 
 
98
 
        switch (reg_res)
99
 
        {
100
 
        case Bonobo_ACTIVATION_REG_ALREADY_ACTIVE:
101
 
        {
102
 
                gchar *newargv[1];
103
 
                int i;
104
 
                
105
 
                bonobo_object_unref (BONOBO_OBJECT (*app));
106
 
                *app = NULL;
107
 
                
108
 
                newargv[0] = startup_id;
109
 
                i = bonobo_app_client_new_instance (client,
110
 
                        ((newargv[0] && newargv[0][0] != '\0') ? 1 : 0), newargv, NULL);
111
 
                g_object_unref (client);
112
 
                return TRUE;
113
 
        }
114
 
        case Bonobo_ACTIVATION_REG_SUCCESS:
115
 
                return FALSE;
116
 
                break;
117
 
 
118
 
        case Bonobo_ACTIVATION_REG_ERROR:
119
 
        default:
120
 
                g_error ("bonobo activation error when registering unique application");
121
 
                return FALSE;
122
 
        }
123
 
}