~ubuntu-branches/ubuntu/raring/remmina/raring

« back to all changes in this revision

Viewing changes to src/remminawidgetpool.c

  • Committer: Package Import Robot
  • Author(s): Luca Falavigna
  • Date: 2012-02-11 17:28:48 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20120211172848-rh3ffi7075qyobuq
Tags: 1.0.0-1
* New upstream release.
  - Compatible with FreeRDP 1.0 (Closes: #658363).
  - Ported to GTK3, this also fixes an incompatibility with
    GTK2 and recent Avahi with GTK3 support, which lead to
    crashes when scanning network services (Closes: #626499).
* debian/patches/libvncserver.patch:
  - Do not use convenience copy of libvncserver.
* debian/patches/g_thread_init.patch:
  - Do not use deprecated g_thread_init function.
* debian/patches/REMMINA_COMMAND_NONE.patch:
  - Removed, obsoleted by GApplication port.
* debian/clean:
  - Remove spurious files created at build-time.
* debian/compat:
  - Bump compatibility level to 9.
* debian/control:
  - Refresh build-dependencies to match new structure.
  - Drop remmina-dev package, no longer used.
  - Build packages once provided by remmina-plugins.
  - Provide remmina-common package.
  - Provide remmina-plugin-gnome package.
* debian/copyright:
  - Refresh copyright information.
* debian/docs:
  - Documentation is no longer accurate, do not ship it anymore.
* debian/remmina-dev.install:
  - Drop remmina-dev package, no longer used.
* debian/remmina-plugin-telepathy.install:
  - Adjust location for Remmina.client.
  - Disable D-BUS support for now.
* debian/rules:
  - Compile with -DWITH_APPINDICATOR=OFF.
  - Do not treat plugins as shared libraries.
* debian/watch:
  - Adjust watch file to match new download location.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Remmina - The GTK+ Remote Desktop Client
3
 
 * Copyright (C) 2009 - Vic Lee 
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, 
18
 
 * Boston, MA 02111-1307, USA.
19
 
 */
20
 
 
21
 
#include <gtk/gtk.h>
22
 
#include "remminapublic.h"
23
 
#include "remminawidgetpool.h"
24
 
 
25
 
static GPtrArray *remmina_widget_pool = NULL;
26
 
 
27
 
static guint remmina_widget_pool_try_quit_handler = 0;
28
 
 
29
 
static gboolean remmina_widget_pool_on_hold = FALSE;
30
 
 
31
 
static gboolean
32
 
remmina_widget_pool_try_quit (gpointer data)
33
 
{
34
 
    if (remmina_widget_pool->len == 0 && !remmina_widget_pool_on_hold)
35
 
    {
36
 
        gtk_main_quit ();
37
 
    }
38
 
    remmina_widget_pool_try_quit_handler = 0;
39
 
    return FALSE;
40
 
}
41
 
 
42
 
void
43
 
remmina_widget_pool_init (void)
44
 
{
45
 
    remmina_widget_pool = g_ptr_array_new ();
46
 
    remmina_widget_pool_try_quit_handler = g_timeout_add (15000, remmina_widget_pool_try_quit, NULL);
47
 
}
48
 
 
49
 
static void
50
 
remmina_widget_pool_on_widget_destroy (GtkWidget *widget, gpointer data)
51
 
{
52
 
    g_ptr_array_remove (remmina_widget_pool, widget);
53
 
    if (remmina_widget_pool->len == 0 && remmina_widget_pool_try_quit_handler == 0)
54
 
    {
55
 
        /* Wait for a while to make sure no more windows will open before we quit the application */
56
 
        remmina_widget_pool_try_quit_handler = g_timeout_add (10000, remmina_widget_pool_try_quit, NULL);
57
 
    }
58
 
}
59
 
 
60
 
void
61
 
remmina_widget_pool_register (GtkWidget *widget)
62
 
{
63
 
    g_ptr_array_add (remmina_widget_pool, widget);
64
 
    g_signal_connect (G_OBJECT (widget), "destroy", G_CALLBACK (remmina_widget_pool_on_widget_destroy), NULL);
65
 
    if (remmina_widget_pool_try_quit_handler)
66
 
    {
67
 
        g_source_remove (remmina_widget_pool_try_quit_handler);
68
 
        remmina_widget_pool_try_quit_handler = 0;
69
 
    }
70
 
}
71
 
 
72
 
GtkWidget*
73
 
remmina_widget_pool_find (GType type, const gchar *tag)
74
 
{
75
 
    GtkWidget *widget;
76
 
    gint i;
77
 
    GdkScreen *screen;
78
 
    gint screen_number;
79
 
    guint workspace;
80
 
 
81
 
    screen = gdk_screen_get_default ();
82
 
    screen_number = gdk_screen_get_number (screen);
83
 
    workspace = remmina_public_get_current_workspace (screen);
84
 
 
85
 
    if (remmina_widget_pool == NULL) return NULL;
86
 
 
87
 
    for (i = 0; i < remmina_widget_pool->len; i++)
88
 
    {
89
 
        widget = GTK_WIDGET (g_ptr_array_index (remmina_widget_pool, i));
90
 
        if (!G_TYPE_CHECK_INSTANCE_TYPE (widget, type)) continue;
91
 
        if (screen_number != gdk_screen_get_number (gtk_window_get_screen (GTK_WINDOW (widget)))) continue;
92
 
        if (workspace != remmina_public_get_window_workspace (GTK_WINDOW (widget))) continue;
93
 
        if (tag && g_strcmp0 ((const gchar*) g_object_get_data (G_OBJECT (widget), "tag"), tag) != 0) continue;
94
 
        return widget;
95
 
    }
96
 
    return NULL;
97
 
}
98
 
 
99
 
GtkWidget*
100
 
remmina_widget_pool_find_by_window (GType type, GdkWindow *window)
101
 
{
102
 
    GtkWidget *widget;
103
 
    gint i;
104
 
    GdkWindow *parent;
105
 
 
106
 
    if (window == NULL || remmina_widget_pool == NULL) return NULL;
107
 
 
108
 
    for (i = 0; i < remmina_widget_pool->len; i++)
109
 
    {
110
 
        widget = GTK_WIDGET (g_ptr_array_index (remmina_widget_pool, i));
111
 
        if (!G_TYPE_CHECK_INSTANCE_TYPE (widget, type)) continue;
112
 
        /* gdk_window_get_toplevel won't work here, if the window is an embedded client. So we iterate the window tree */
113
 
        for (parent = window; parent && parent != GDK_WINDOW_ROOT; parent = gdk_window_get_parent (parent))
114
 
        {
115
 
            if (gtk_widget_get_window (widget) == parent) return widget;
116
 
        }
117
 
    }
118
 
    return NULL;
119
 
}
120
 
 
121
 
void
122
 
remmina_widget_pool_hold (gboolean hold)
123
 
{
124
 
    remmina_widget_pool_on_hold = hold;
125
 
    if (!hold && remmina_widget_pool_try_quit_handler == 0)
126
 
    {
127
 
        remmina_widget_pool_try_quit_handler = g_timeout_add (10000, remmina_widget_pool_try_quit, NULL);
128
 
    }
129
 
}
130
 
 
131
 
gint
132
 
remmina_widget_pool_foreach (RemminaWidgetPoolForEachFunc callback, gpointer data)
133
 
{
134
 
    GtkWidget *widget;
135
 
    gint i;
136
 
    gint n = 0;
137
 
 
138
 
    if (remmina_widget_pool == NULL) return 0;
139
 
 
140
 
    for (i = 0; i < remmina_widget_pool->len; i++)
141
 
    {
142
 
        widget = GTK_WIDGET (g_ptr_array_index (remmina_widget_pool, i));
143
 
        if  (callback (widget, data)) n++;
144
 
    }
145
 
    return n;
146
 
}
147