/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/GPumpApp.c

  • Committer: Gustav Hatvigsson
  • Date: 2014-04-14 07:33:32 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140414073332-eagun3d8y56k3dtd
* Switched to GKeyFile instead of GSettings, for the time being.

** This is untested code **

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 */
5
5
 
6
6
#include "GPumpApp.h"
 
7
#include "GPumpSettings.h"
 
8
#include "GPumpSettingsData.h"
7
9
 
8
 
#define GPUMP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((GPumpApp *) obj)->priv)
 
10
#define GPUMP_APP_GET_PRIVATE(obj)\
 
11
  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GPUMP_TYPE_APP, GPumpAppPrivate))
9
12
 
10
13
G_DEFINE_TYPE (GPumpApp, gpump_app, GTK_TYPE_APPLICATION)
11
14
 
12
15
struct GPumpAppPrivate {
13
16
  
14
 
  GSettings * ui_settings;
15
 
  GSettings * login_settings;
16
 
  
17
17
  /* Widgets */
18
18
  GtkWidget * window;
19
19
  GtkWidget * header_bar;
20
20
  GtkWidget * layout; /* GtkBox */
21
 
  GtkWidget * post_list_view; /* GtkTreeView */
 
21
  GtkWidget * scroll_view; /* GtkScrolledWindow */
 
22
  GtkWidget * post_list_box; /* GtkListBox */
 
23
  GtkWidget * btn_gear; /* GtkMenuButton */
 
24
  GtkWidget * btn_new_post;
 
25
  GtkWidget * btn_refresh;
 
26
  
 
27
  /* gear menu */
 
28
  GtkWidget * gear_menu; /* GtkMenu */
 
29
  
 
30
  /* List store */
22
31
  GtkListStore * post_list_store;
23
32
};
24
33
 
 
34
typedef enum {
 
35
  GPUPM_APP_MAIN_LIST_COL = 0,
 
36
  GPUMP_APP_MAIN_LIST_NUM_COL
 
37
} GPumpAppCols;
 
38
 
 
39
 
 
40
 
25
41
/* * Callback and private function declarations *******************************/
26
42
void gpump_app_class_init (GPumpAppClass * klass);
27
43
void gpump_app_activate (GApplication * application);
28
44
void gpump_app_init (GPumpApp * self);
29
45
 
 
46
void _prepere_window (GPumpApp * self);
 
47
void _prepere_gear_menu (GPumpApp * self);
 
48
void _prepere_new_post_button (GPumpApp * self);
 
49
void _prepere_refresh_button (GPumpApp * self);
 
50
void _prepere_app_menu (GPumpApp * self);
 
51
 
 
52
void _cb_show_settings (GSimpleAction * action, GVariant * parameter,
 
53
                        gpointer user_data);
 
54
void _cb_do_nothing (GSimpleAction * action, GVariant * parameter,
 
55
                        gpointer user_data);
 
56
void _cb_quit (GSimpleAction * action, GVariant * parameter,
 
57
                        gpointer user_data);
 
58
 
30
59
/* * Class functions **********************************************************/
31
60
GPumpApp * gpump_app_new (void) {
32
61
  GPumpApp * self = g_object_new (GPUMP_TYPE_APP,
37
66
}
38
67
 
39
68
void gpump_app_init (GPumpApp * self) {
 
69
  g_print ("init\n");
 
70
  self->priv = GPUMP_APP_GET_PRIVATE (self);
40
71
  
41
72
}
42
73
 
48
79
  
49
80
  application_class->activate = gpump_app_activate;
50
81
  
51
 
  g_type_class_add_private (klass, sizeof(GPumpApp));
 
82
  g_type_class_add_private (klass, sizeof(GPumpAppPrivate));
52
83
  
53
84
  g_print ("GPumpApp class init done.\n");
54
85
}
57
88
void gpump_app_activate (GApplication * application) {
58
89
  g_print ("GPumpApp activate.\n");
59
90
  
60
 
  
 
91
  /* Check for uniques of window */
 
92
  GList * w_list = gtk_application_get_windows (GTK_APPLICATION(application));
 
93
  if (w_list) {
 
94
    gtk_window_present (GTK_WINDOW (w_list->data));
 
95
    return;
 
96
  }
 
97
  
 
98
  g_list_free (w_list);
 
99
  
 
100
  /* Prepere stuff */
 
101
  _prepere_window (GPUMP_APP (application));
 
102
  _prepere_gear_menu (GPUMP_APP (application));
 
103
  _prepere_app_menu (GPUMP_APP (application));
 
104
  _prepere_new_post_button (GPUMP_APP (application));
 
105
  _prepere_refresh_button (GPUMP_APP (application));
 
106
  
 
107
  /* Show it! */
 
108
  gtk_widget_show_all (GTK_WIDGET(GPUMP_APP(application)->priv->window));
61
109
  
62
110
  g_print ("done GPumpApp activate.\n");
63
111
}
64
112
 
65
 
 
 
113
void _prepere_window (GPumpApp * self) {
 
114
  GPumpAppPrivate * priv = self->priv;
 
115
  GtkWidget * window = priv->window =
 
116
    gtk_application_window_new (GTK_APPLICATION (self));
 
117
  GtkWidget * header_bar = priv->header_bar = gtk_header_bar_new ();
 
118
  GtkWidget * layout = priv->layout =
 
119
    gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
 
120
  
 
121
  gtk_header_bar_set_title (GTK_HEADER_BAR (header_bar), "GPump");
 
122
  gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header_bar),
 
123
                               _("A Pump.io Client"));
 
124
  gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), TRUE);
 
125
  
 
126
  GtkWidget * scroll = priv->post_list_box =
 
127
    gtk_scrolled_window_new (NULL, NULL);
 
128
  
 
129
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
 
130
    GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
 
131
  
 
132
  GtkWidget * post_list_box = priv->post_list_box =
 
133
    gtk_list_box_new ();
 
134
  
 
135
  gtk_container_add (GTK_CONTAINER(scroll), post_list_box);
 
136
  
 
137
  gtk_window_set_titlebar (GTK_WINDOW (window), header_bar);
 
138
  gtk_window_set_default_size (GTK_WINDOW(window), 500,500);
 
139
  
 
140
  gtk_box_pack_start (GTK_BOX (layout), scroll, TRUE, TRUE, 1);
 
141
  
 
142
  gtk_container_add (GTK_CONTAINER (window), layout);
 
143
  
 
144
  /* Hide window instead of destroying it */
 
145
  g_signal_connect (G_OBJECT (window), "delete_event" ,
 
146
                  G_CALLBACK (gtk_widget_hide_on_delete), self);
 
147
}
 
148
 
 
149
void _prepere_app_menu (GPumpApp * self) {
 
150
  /* App menu actions */
 
151
  const GActionEntry _app_actions[] = {
 
152
    {"settings", _cb_show_settings},
 
153
    {"about", _cb_do_nothing},
 
154
    {"quit", _cb_quit}
 
155
  };
 
156
  
 
157
  /* Map actions to application ... I do not know... :-S */
 
158
  g_action_map_add_action_entries (G_ACTION_MAP (self), _app_actions,
 
159
    G_N_ELEMENTS(_app_actions), GTK_APPLICATION(self));
 
160
  
 
161
  GMenu * menu = g_menu_new ();
 
162
  
 
163
  g_menu_append (menu, _("Settings"), "app.settings");
 
164
  g_menu_append (menu, _("About"), "app.about");
 
165
  g_menu_append (menu, _("Quit"), "app.quit");
 
166
  
 
167
  gtk_application_set_app_menu (GTK_APPLICATION (self), G_MENU_MODEL (menu));
 
168
  g_object_unref (menu);
 
169
}
 
170
 
 
171
void _prepere_gear_menu (GPumpApp * self) {
 
172
  GPumpAppPrivate * priv = self->priv;
 
173
  
 
174
  /* Create menu and menu items. */
 
175
  priv->gear_menu = gtk_menu_new();
 
176
  GtkWidget * mi_profiles = gtk_menu_item_new_with_label (_("Profiles"));
 
177
  
 
178
  
 
179
  /* Add items to menu. */
 
180
  gtk_container_add (GTK_CONTAINER (priv->gear_menu), mi_profiles);
 
181
  
 
182
  /* I have no idea why we need to run these, it seems trange, this
 
183
   * should be handled by the caller of gtk_
 
184
   */
 
185
  gtk_widget_show (GTK_WIDGET(mi_profiles));
 
186
  
 
187
  /* Hook up signals. */
 
188
  /*
 
189
  g_signal_connect (G_OBJECT (mi_profiles), "activate",
 
190
                    NULL, self);
 
191
  */
 
192
  
 
193
  /* create and attatch the gear menu button */
 
194
  priv->btn_gear = gtk_menu_button_new ();
 
195
  gtk_menu_button_set_popup (GTK_MENU_BUTTON (priv->btn_gear),
 
196
    GTK_WIDGET(priv->gear_menu));
 
197
  gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header_bar), priv->btn_gear);
 
198
  
 
199
  /* Setting icon */
 
200
  GtkWidget * gear_icon = gtk_image_new_from_icon_name(
 
201
    "emblem-system-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
 
202
  gtk_button_set_image (GTK_BUTTON (priv->btn_gear), gear_icon);
 
203
  
 
204
  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_gear), _("GPump gear menu"));
 
205
}
 
206
 
 
207
void _prepere_new_post_button (GPumpApp * self) {
 
208
  GPumpAppPrivate * priv = self->priv;
 
209
  
 
210
  GtkWidget * share_icon = gtk_image_new_from_icon_name ("text-editor-symbolic",
 
211
    GTK_ICON_SIZE_LARGE_TOOLBAR);
 
212
  priv->btn_new_post = gtk_button_new ();
 
213
  gtk_button_set_image (GTK_BUTTON (priv->btn_new_post), share_icon);
 
214
  
 
215
  gtk_header_bar_pack_start (GTK_HEADER_BAR (priv->header_bar),
 
216
    priv->btn_new_post);
 
217
  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_new_post),
 
218
    _("Create new post"));
 
219
}
 
220
 
 
221
void _prepere_refresh_button (GPumpApp * self) {
 
222
  GPumpAppPrivate * priv = self->priv;
 
223
  GtkWidget * refresh_icon = gtk_image_new_from_icon_name
 
224
    ("emblem-synchronizing-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
 
225
  priv->btn_refresh = gtk_button_new ();
 
226
  gtk_button_set_image (GTK_BUTTON (priv->btn_refresh), refresh_icon);
 
227
  gtk_header_bar_pack_start (GTK_HEADER_BAR(priv->header_bar),
 
228
    priv->btn_refresh);
 
229
  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_refresh),
 
230
    _("Refresh the stream"));
 
231
}
66
232
 
67
233
/* * Callback implemenations **************************************************/
 
234
void _cb_show_settings (GSimpleAction * action, GVariant * parameter,
 
235
                        gpointer user_data) {
 
236
  GPumpApp * self = GPUMP_APP (user_data);
 
237
  GPumpSettings * settings = gpump_settings_new (self->priv->window);
 
238
  gpump_settings_show (settings);
 
239
}
 
240
 
 
241
void _cb_do_nothing (GSimpleAction * action, GVariant * parameter,
 
242
                        gpointer user_data) {}
 
243
 
 
244
void _cb_quit (GSimpleAction * action, GVariant * parameter,
 
245
                        gpointer user_data) {
 
246
  g_application_quit (G_APPLICATION(user_data));
 
247
}
68
248