/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 Hartvigsson
  • Date: 2014-02-09 20:15:21 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140209201521-mvjdpy9lpkguhft7
* changed the icons in the widget UI to Symoblic.
* changed from GtkTreeView to GtkListBox. This should make things
  in the future

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"
9
7
 
10
8
#define GPUMP_APP_GET_PRIVATE(obj)\
11
9
  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GPUMP_TYPE_APP, GPumpAppPrivate))
14
12
 
15
13
struct GPumpAppPrivate {
16
14
  
 
15
  GSettings * ui_settings;
 
16
  GSettings * login_settings;
 
17
  
17
18
  /* Widgets */
18
19
  GtkWidget * window;
19
20
  GtkWidget * header_bar;
47
48
void _prepere_gear_menu (GPumpApp * self);
48
49
void _prepere_new_post_button (GPumpApp * self);
49
50
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
51
 
59
52
/* * Class functions **********************************************************/
60
53
GPumpApp * gpump_app_new (void) {
87
80
 
88
81
void gpump_app_activate (GApplication * application) {
89
82
  g_print ("GPumpApp activate.\n");
90
 
  
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);
 
83
 
99
84
  
100
85
  /* Prepere stuff */
101
86
  _prepere_window (GPUMP_APP (application));
102
87
  _prepere_gear_menu (GPUMP_APP (application));
103
 
  _prepere_app_menu (GPUMP_APP (application));
104
88
  _prepere_new_post_button (GPUMP_APP (application));
105
89
  _prepere_refresh_button (GPUMP_APP (application));
106
90
  
110
94
  g_print ("done GPumpApp activate.\n");
111
95
}
112
96
 
 
97
void _prepere_gear_menu (GPumpApp * self) {
 
98
  GPumpAppPrivate * priv = self->priv;
 
99
 
 
100
  /* create the menu model */
 
101
  GMenu * menu_model = g_menu_new ();
 
102
  g_menu_append (menu_model, "Profiles", NULL);
 
103
  g_menu_append (menu_model, "Settings", NULL);
 
104
  
 
105
  priv->gear_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu_model));
 
106
  g_object_unref (menu_model);
 
107
  
 
108
  /* create and attatch the gear menu button */
 
109
  priv->btn_gear = gtk_menu_button_new ();
 
110
  gtk_menu_button_set_popup (GTK_MENU_BUTTON(priv->btn_gear),
 
111
    GTK_WIDGET(priv->gear_menu));
 
112
  gtk_header_bar_pack_end (GTK_HEADER_BAR(priv->header_bar), priv->btn_gear);
 
113
  
 
114
  /* Setting icon */
 
115
  GtkWidget * gear_icon = gtk_image_new_from_icon_name(
 
116
    "emblem-system-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
 
117
  gtk_button_set_image (GTK_BUTTON (priv->btn_gear), gear_icon);
 
118
  
 
119
  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_gear), "GPupm gear menu");
 
120
}
 
121
 
 
122
void _prepere_new_post_button (GPumpApp * self) {
 
123
  GPumpAppPrivate * priv = self->priv;
 
124
  
 
125
  GtkWidget * share_icon = gtk_image_new_from_icon_name ("text-editor-symbolic",
 
126
    GTK_ICON_SIZE_LARGE_TOOLBAR);
 
127
  priv->btn_new_post = gtk_button_new ();
 
128
  gtk_button_set_image (GTK_BUTTON (priv->btn_new_post), share_icon);
 
129
  
 
130
  gtk_header_bar_pack_start (GTK_HEADER_BAR (priv->header_bar),
 
131
    priv->btn_new_post);
 
132
  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_new_post),
 
133
    "Create new post");
 
134
}
 
135
 
113
136
void _prepere_window (GPumpApp * self) {
114
137
  GPumpAppPrivate * priv = self->priv;
115
138
  GtkWidget * window = priv->window =
119
142
    gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
120
143
  
121
144
  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
145
  gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), TRUE);
125
146
  
126
147
  GtkWidget * scroll = priv->post_list_box =
131
152
  
132
153
  GtkWidget * post_list_box = priv->post_list_box =
133
154
    gtk_list_box_new ();
 
155
 
134
156
  
135
157
  gtk_container_add (GTK_CONTAINER(scroll), post_list_box);
136
158
  
137
159
  gtk_window_set_titlebar (GTK_WINDOW (window), header_bar);
138
 
  gtk_window_set_default_size (GTK_WINDOW(window), 500,500);
 
160
  gtk_widget_set_size_request (window, 500,500);
139
161
  
140
162
  gtk_box_pack_start (GTK_BOX (layout), scroll, TRUE, TRUE, 1);
141
163
  
142
164
  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
165
}
220
166
 
221
167
void _prepere_refresh_button (GPumpApp * self) {
224
170
    ("emblem-synchronizing-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
225
171
  priv->btn_refresh = gtk_button_new ();
226
172
  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);
 
173
  gtk_header_bar_pack_start (GTK_HEADER_BAR(priv->header_bar), priv->btn_refresh);
229
174
  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_refresh),
230
 
    _("Refresh the stream"));
 
175
    "Refresh the stream");
231
176
}
232
177
 
233
178
/* * 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
 
}
248
179