~ubuntu-branches/ubuntu/karmic/xfce4-session/karmic

« back to all changes in this revision

Viewing changes to xfce4-session/xfsm-chooser.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2005-11-06 22:01:12 UTC
  • mto: (4.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051106220112-5rusox237ymjghsp
Tags: upstream-4.2.3
ImportĀ upstreamĀ versionĀ 4.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: xfsm-chooser.c 4711 2004-11-01 16:10:55Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2004 Benedikt Meurer <benny@xfce.org>
 
4
 * All rights reserved.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *                                                                              
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *                                                                              
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#ifdef HAVE_MEMORY_H
 
27
#include <memory.h>
 
28
#endif
 
29
#ifdef HAVE_STRING_H
 
30
#include <string.h>
 
31
#endif
 
32
#ifdef HAVE_TIME_H
 
33
#include <time.h>
 
34
#endif
 
35
 
 
36
#include <libxfce4util/libxfce4util.h>
 
37
#include <libxfcegui4/libxfcegui4.h>
 
38
 
 
39
#include <libxfsm/xfsm-splash-engine.h>
 
40
#include <libxfsm/xfsm-util.h>
 
41
 
 
42
#include <xfce4-session/xfsm-chooser.h>
 
43
 
 
44
 
 
45
#define BORDER 6
 
46
 
 
47
 
 
48
static void xfsm_chooser_class_init (XfsmChooserClass *klass);
 
49
static void xfsm_chooser_init (XfsmChooser *chooser);
 
50
static void xfsm_chooser_finalize (GObject *object);
 
51
static void xfsm_chooser_row_activated (GtkTreeView       *treeview,
 
52
                                        GtkTreePath       *path,
 
53
                                        GtkTreeViewColumn *column,
 
54
                                        XfsmChooser       *chooser);
 
55
static void xfsm_chooser_realized      (GtkWidget         *widget,
 
56
                                        XfsmChooser       *chooser);
 
57
 
 
58
 
 
59
enum
 
60
{
 
61
  PREVIEW_COLUMN,
 
62
  NAME_COLUMN,
 
63
  TITLE_COLUMN,
 
64
  ATIME_COLUMN,
 
65
  N_COLUMNS,
 
66
};
 
67
 
 
68
 
 
69
static GObjectClass *parent_class;
 
70
 
 
71
 
 
72
GType
 
73
xfsm_chooser_get_type (void)
 
74
{
 
75
  static GType chooser_type = 0;
 
76
 
 
77
  if (chooser_type == 0)
 
78
    {
 
79
      static const GTypeInfo chooser_info = {
 
80
        sizeof (XfsmChooserClass),
 
81
        NULL,
 
82
        NULL,
 
83
        (GClassInitFunc) xfsm_chooser_class_init,
 
84
        NULL,
 
85
        NULL,
 
86
        sizeof (XfsmChooser),
 
87
        0,
 
88
        (GInstanceInitFunc) xfsm_chooser_init,
 
89
      };
 
90
 
 
91
      chooser_type = g_type_register_static (GTK_TYPE_DIALOG,
 
92
                                             "XfsmChooser",
 
93
                                             &chooser_info,
 
94
                                             0);
 
95
    }
 
96
 
 
97
  return chooser_type;
 
98
}
 
99
 
 
100
 
 
101
void
 
102
xfsm_chooser_set_sessions (XfsmChooser *chooser,
 
103
                           GList       *sessions,
 
104
                           const gchar *default_session)
 
105
{
 
106
  XfsmSessionInfo *session;
 
107
  GtkTreeModel    *model;
 
108
  GtkTreeIter      iter;
 
109
  gchar           *title;
 
110
  GList           *lp;
 
111
 
 
112
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (chooser->tree));
 
113
  gtk_list_store_clear (GTK_LIST_STORE (model));
 
114
 
 
115
  for (lp = sessions; lp != NULL; lp = lp->next)
 
116
    {
 
117
      session = (XfsmSessionInfo *) lp->data;
 
118
 
 
119
      title = g_strdup_printf ("<b><big>%s</big></b>\n"
 
120
                               "<small><i>Last access: %s</i></small>",
 
121
                               session->name, ctime (&session->atime));
 
122
 
 
123
      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
124
      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
125
                          PREVIEW_COLUMN, session->preview,
 
126
                          NAME_COLUMN, session->name,
 
127
                          TITLE_COLUMN, title,
 
128
                          ATIME_COLUMN, session->atime,
 
129
                          -1);
 
130
 
 
131
      g_free (title);
 
132
    }
 
133
}
 
134
 
 
135
 
 
136
gchar*
 
137
xfsm_chooser_get_session (const XfsmChooser *chooser)
 
138
{
 
139
  GtkTreeSelection *selection;
 
140
  GtkTreeModel     *model;
 
141
  GtkTreeIter       iter;
 
142
  GValue            value;
 
143
  gchar            *name;
 
144
 
 
145
  bzero (&value, sizeof (value));
 
146
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chooser->tree));
 
147
  gtk_tree_selection_get_selected (selection, &model, &iter);
 
148
  gtk_tree_model_get_value (model, &iter, NAME_COLUMN, &value);
 
149
  name = g_value_dup_string (&value);
 
150
  g_value_unset (&value);
 
151
 
 
152
  return name;
 
153
}
 
154
 
 
155
 
 
156
static void
 
157
xfsm_chooser_class_init (XfsmChooserClass *klass)
 
158
{
 
159
  GObjectClass *gobject_class;
 
160
 
 
161
  gobject_class = G_OBJECT_CLASS (klass);
 
162
  gobject_class->finalize = xfsm_chooser_finalize;
 
163
 
 
164
  parent_class = gtk_type_class (gtk_dialog_get_type ());
 
165
}
 
166
 
 
167
 
 
168
static void
 
169
xfsm_chooser_init (XfsmChooser *chooser)
 
170
{
 
171
  GtkTreeSelection *selection;
 
172
  GtkTreeViewColumn *column;
 
173
  GtkCellRenderer *renderer;
 
174
  GtkListStore *model;
 
175
  GtkWidget *button;
 
176
  GtkWidget *swin;
 
177
  GtkWidget *dbox;
 
178
 
 
179
  dbox = GTK_DIALOG (chooser)->vbox;
 
180
  
 
181
  gtk_dialog_set_has_separator (GTK_DIALOG (chooser), FALSE);
 
182
  g_signal_connect_after (G_OBJECT (chooser), "realize",
 
183
                          G_CALLBACK (xfsm_chooser_realized), chooser);
 
184
 
 
185
  /* allocate tooltips */
 
186
  chooser->tooltips = gtk_tooltips_new ();
 
187
  g_object_ref (G_OBJECT (chooser->tooltips));
 
188
  gtk_object_sink (GTK_OBJECT (chooser->tooltips));
 
189
 
 
190
  /* scrolled window */
 
191
  swin = gtk_scrolled_window_new (NULL, NULL);
 
192
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), 
 
193
                                  GTK_POLICY_NEVER,
 
194
                                  GTK_POLICY_AUTOMATIC);
 
195
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
 
196
                                       GTK_SHADOW_ETCHED_IN);
 
197
  gtk_box_pack_start (GTK_BOX (dbox), swin, TRUE, TRUE, 0);
 
198
  gtk_widget_show (swin);
 
199
 
 
200
  /* tree view */
 
201
  model = gtk_list_store_new (N_COLUMNS,
 
202
                              GDK_TYPE_PIXBUF,
 
203
                              G_TYPE_STRING,
 
204
                              G_TYPE_STRING,
 
205
                              G_TYPE_INT);
 
206
  chooser->tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(model));
 
207
  g_object_unref (G_OBJECT (model));
 
208
  gtk_tooltips_set_tip (chooser->tooltips, chooser->tree,
 
209
                        _("Choose the session you want to restore. "
 
210
                          "You can simply double-click the session "
 
211
                          "name to restore it."),
 
212
                        NULL);
 
213
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (chooser->tree), FALSE);
 
214
  column = gtk_tree_view_column_new ();
 
215
  renderer = gtk_cell_renderer_pixbuf_new ();
 
216
  gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
217
  gtk_tree_view_column_set_attributes (column, renderer,
 
218
                                       "pixbuf", PREVIEW_COLUMN,
 
219
                                       NULL);
 
220
  renderer = gtk_cell_renderer_text_new ();
 
221
  gtk_tree_view_column_pack_start (column, renderer, TRUE);
 
222
  gtk_tree_view_column_set_attributes (column, renderer,
 
223
                                       "markup", TITLE_COLUMN,
 
224
                                       NULL);
 
225
  gtk_tree_view_append_column (GTK_TREE_VIEW (chooser->tree), column);
 
226
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chooser->tree));
 
227
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
 
228
  g_signal_connect (G_OBJECT (chooser->tree), "row-activated",
 
229
                    G_CALLBACK (xfsm_chooser_row_activated), chooser);
 
230
  gtk_container_add (GTK_CONTAINER (swin), chooser->tree);
 
231
  gtk_widget_set_size_request (chooser->tree, -1, 150);
 
232
  gtk_widget_show (chooser->tree);
 
233
 
 
234
  /* "Logout" button */
 
235
  button = xfsm_imgbtn_new (_("Logout"), GTK_STOCK_QUIT, NULL);
 
236
  gtk_tooltips_set_tip (chooser->tooltips, button,
 
237
                        _("Cancel the login attempt and return to "
 
238
                          "the login screen."),
 
239
                        NULL);
 
240
  gtk_dialog_add_action_widget (GTK_DIALOG (chooser), button,
 
241
                                GTK_RESPONSE_CANCEL);
 
242
  gtk_widget_show (button);
 
243
 
 
244
  /* "New" button */
 
245
  button = xfsm_imgbtn_new (_("New session"), GTK_STOCK_NEW, NULL);
 
246
  gtk_tooltips_set_tip (chooser->tooltips, button,
 
247
                        _("Create a new session."),
 
248
                        NULL);
 
249
  gtk_dialog_add_action_widget (GTK_DIALOG (chooser), button,
 
250
                                XFSM_RESPONSE_NEW);
 
251
  gtk_widget_show (button);
 
252
}
 
253
 
 
254
 
 
255
static void
 
256
xfsm_chooser_finalize (GObject *object)
 
257
{
 
258
  XfsmChooser *chooser;
 
259
 
 
260
  chooser = XFSM_CHOOSER (object);
 
261
  g_object_unref (chooser->tooltips);
 
262
 
 
263
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
264
}
 
265
 
 
266
 
 
267
static void
 
268
xfsm_chooser_row_activated (GtkTreeView       *treeview,
 
269
                            GtkTreePath       *path,
 
270
                            GtkTreeViewColumn *column,
 
271
                            XfsmChooser       *chooser)
 
272
{
 
273
  gtk_dialog_response (GTK_DIALOG (chooser), XFSM_RESPONSE_LOAD);
 
274
}
 
275
 
 
276
 
 
277
static void
 
278
xfsm_chooser_realized (GtkWidget   *widget,
 
279
                       XfsmChooser *chooser)
 
280
{
 
281
  GdkCursor *cursor;
 
282
 
 
283
  cursor = gdk_cursor_new (GDK_LEFT_PTR);
 
284
  gdk_window_set_cursor (widget->window, cursor);
 
285
  gdk_cursor_unref (cursor);
 
286
}
 
287