bzr branch
http://gegoxaren.bato24.eu/bzr/gpump/trunk
|
1
by Gustav Hartvigsson
Initial code. |
1 |
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
|
2 |
* vi: set shiftwidth=2 tabstop=2 expandtab:
|
|
3 |
* :indentSize=2:tabSize=2:noTabs=true:
|
|
4 |
*/
|
|
5 |
||
6 |
#include "GPumpApp.h" |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
7 |
#include "GPumpSettings.h" |
|
20
by Gustav Hatvigsson
* Added a singeltonian class to keep settings data in. |
8 |
#include "GPumpSettingsData.h" |
|
1
by Gustav Hartvigsson
Initial code. |
9 |
|
|
6
by Gustav Hartvigsson
There we go. |
10 |
#define GPUMP_APP_GET_PRIVATE(obj)\
|
11 |
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GPUMP_TYPE_APP, GPumpAppPrivate))
|
|
|
1
by Gustav Hartvigsson
Initial code. |
12 |
|
13 |
G_DEFINE_TYPE (GPumpApp, gpump_app, GTK_TYPE_APPLICATION) |
|
14 |
||
15 |
struct GPumpAppPrivate { |
|
16 |
|
|
17 |
/* Widgets */ |
|
18 |
GtkWidget * window; |
|
19 |
GtkWidget * header_bar; |
|
20 |
GtkWidget * layout; /* GtkBox */ |
|
|
10
by Gustav Hartvigsson
changed form GtkTreeView to GtkListBox. |
21 |
GtkWidget * scroll_view; /* GtkScrolledWindow */ |
22 |
GtkWidget * post_list_box; /* GtkListBox */ |
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
23 |
GtkWidget * btn_gear; /* GtkMenuButton */ |
|
4
by Gustav Hartvigsson
Fixed the probelms I have been having. |
24 |
GtkWidget * btn_new_post; |
|
9
by Gustav Hartvigsson
Added a refresh button |
25 |
GtkWidget * btn_refresh; |
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
26 |
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
27 |
/* gear menu */ |
28 |
GtkWidget * gear_menu; /* GtkMenu */ |
|
29 |
|
|
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
30 |
/* List store */ |
|
1
by Gustav Hartvigsson
Initial code. |
31 |
GtkListStore * post_list_store; |
32 |
};
|
|
33 |
||
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
34 |
typedef enum { |
35 |
GPUPM_APP_MAIN_LIST_COL = 0, |
|
36 |
GPUMP_APP_MAIN_LIST_NUM_COL |
|
37 |
} GPumpAppCols; |
|
38 |
||
39 |
||
40 |
||
|
1
by Gustav Hartvigsson
Initial code. |
41 |
/* * Callback and private function declarations *******************************/
|
42 |
void gpump_app_class_init (GPumpAppClass * klass); |
|
43 |
void gpump_app_activate (GApplication * application); |
|
44 |
void gpump_app_init (GPumpApp * self); |
|
45 |
||
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
46 |
void _prepere_window (GPumpApp * self); |
47 |
void _prepere_gear_menu (GPumpApp * self); |
|
48 |
void _prepere_new_post_button (GPumpApp * self); |
|
|
9
by Gustav Hartvigsson
Added a refresh button |
49 |
void _prepere_refresh_button (GPumpApp * self); |
|
16
by Gustav Hatvigsson
* Moved the settings item from the gear menu to the Application |
50 |
void _prepere_app_menu (GPumpApp * self); |
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
51 |
|
|
16
by Gustav Hatvigsson
* Moved the settings item from the gear menu to the Application |
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); |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
58 |
|
|
1
by Gustav Hartvigsson
Initial code. |
59 |
/* * Class functions **********************************************************/
|
60 |
GPumpApp * gpump_app_new (void) { |
|
61 |
GPumpApp * self = g_object_new (GPUMP_TYPE_APP, |
|
62 |
"application-id", "org.gego.gpump", |
|
63 |
"flags",G_APPLICATION_FLAGS_NONE, |
|
64 |
NULL); |
|
65 |
return self; |
|
66 |
}
|
|
67 |
||
68 |
void gpump_app_init (GPumpApp * self) { |
|
|
5
by Gustav Hartvigsson
Nope... Did not fix it... |
69 |
g_print ("init\n"); |
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
70 |
self->priv = GPUMP_APP_GET_PRIVATE (self); |
|
5
by Gustav Hartvigsson
Nope... Did not fix it... |
71 |
|
|
1
by Gustav Hartvigsson
Initial code. |
72 |
}
|
73 |
||
74 |
void gpump_app_class_init (GPumpAppClass * klass) { |
|
75 |
g_print("GPumpApp class init.\n"); |
|
76 |
|
|
77 |
// GObject * object_class = G_OBJECT_CLASS (klass); |
|
78 |
GApplicationClass * application_class = G_APPLICATION_CLASS (klass); |
|
79 |
|
|
80 |
application_class->activate = gpump_app_activate; |
|
81 |
|
|
|
6
by Gustav Hartvigsson
There we go. |
82 |
g_type_class_add_private (klass, sizeof(GPumpAppPrivate)); |
|
1
by Gustav Hartvigsson
Initial code. |
83 |
|
84 |
g_print ("GPumpApp class init done.\n"); |
|
85 |
}
|
|
86 |
||
87 |
||
88 |
void gpump_app_activate (GApplication * application) { |
|
89 |
g_print ("GPumpApp activate.\n"); |
|
|
17
by Gustav Hatvigsson
* Made GPump single instance. |
90 |
|
91 |
/* Check for uniques of window */ |
|
|
19
by Gustav Hatvigsson
* Started work on GPumpAuth authentication widget, much to do... |
92 |
GList * w_list = gtk_application_get_windows (GTK_APPLICATION(application)); |
|
17
by Gustav Hatvigsson
* Made GPump single instance. |
93 |
if (w_list) { |
94 |
gtk_window_present (GTK_WINDOW (w_list->data)); |
|
95 |
return; |
|
96 |
} |
|
97 |
|
|
98 |
g_list_free (w_list); |
|
99 |
|
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
100 |
/* Prepere stuff */ |
|
8
by Gustav Hartvigsson
moved the UI building to its own private function |
101 |
_prepere_window (GPUMP_APP (application)); |
102 |
_prepere_gear_menu (GPUMP_APP (application)); |
|
|
16
by Gustav Hatvigsson
* Moved the settings item from the gear menu to the Application |
103 |
_prepere_app_menu (GPUMP_APP (application)); |
|
8
by Gustav Hartvigsson
moved the UI building to its own private function |
104 |
_prepere_new_post_button (GPUMP_APP (application)); |
|
9
by Gustav Hartvigsson
Added a refresh button |
105 |
_prepere_refresh_button (GPUMP_APP (application)); |
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
106 |
|
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
107 |
/* Show it! */ |
|
8
by Gustav Hartvigsson
moved the UI building to its own private function |
108 |
gtk_widget_show_all (GTK_WIDGET(GPUMP_APP(application)->priv->window)); |
|
1
by Gustav Hartvigsson
Initial code. |
109 |
|
110 |
g_print ("done GPumpApp activate.\n"); |
|
111 |
}
|
|
112 |
||
|
15
by Gustav Hatvigsson
* changed order of functions to be easier to find. |
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"); |
|
|
18
by Gustav Hatvigsson
* Added a subtitle to the headerbar. |
122 |
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header_bar), |
123 |
_("A Pump.io Client")); |
|
|
15
by Gustav Hatvigsson
* changed order of functions to be easier to find. |
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); |
|
|
19
by Gustav Hatvigsson
* Started work on GPumpAuth authentication widget, much to do... |
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); |
|
|
15
by Gustav Hatvigsson
* changed order of functions to be easier to find. |
147 |
}
|
148 |
||
|
16
by Gustav Hatvigsson
* Moved the settings item from the gear menu to the Application |
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 |
||
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
171 |
void _prepere_gear_menu (GPumpApp * self) { |
172 |
GPumpAppPrivate * priv = self->priv; |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
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. */ |
|
|
19
by Gustav Hatvigsson
* Started work on GPumpAuth authentication widget, much to do... |
188 |
/* |
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
189 |
g_signal_connect (G_OBJECT (mi_profiles), "activate",
|
190 |
NULL, self);
|
|
|
19
by Gustav Hatvigsson
* Started work on GPumpAuth authentication widget, much to do... |
191 |
*/
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
192 |
|
193 |
/* create and attatch the gear menu button */ |
|
194 |
priv->btn_gear = gtk_menu_button_new (); |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
195 |
gtk_menu_button_set_popup (GTK_MENU_BUTTON (priv->btn_gear), |
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
196 |
GTK_WIDGET(priv->gear_menu)); |
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
197 |
gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header_bar), priv->btn_gear); |
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
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); |
|
|
11
by Gustav Hartvigsson
Added tooltips to the buttons in the header bar. |
203 |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
204 |
gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_gear), _("GPump gear menu")); |
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
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); |
|
|
11
by Gustav Hartvigsson
Added tooltips to the buttons in the header bar. |
217 |
gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_new_post), |
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
218 |
_("Create new post")); |
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
219 |
}
|
220 |
||
|
9
by Gustav Hartvigsson
Added a refresh button |
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); |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
227 |
gtk_header_bar_pack_start (GTK_HEADER_BAR(priv->header_bar), |
228 |
priv->btn_refresh); |
|
|
11
by Gustav Hartvigsson
Added tooltips to the buttons in the header bar. |
229 |
gtk_widget_set_tooltip_text (GTK_WIDGET (priv->btn_refresh), |
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
230 |
_("Refresh the stream")); |
|
9
by Gustav Hartvigsson
Added a refresh button |
231 |
}
|
232 |
||
|
1
by Gustav Hartvigsson
Initial code. |
233 |
/* * Callback implemenations **************************************************/
|
|
16
by Gustav Hatvigsson
* Moved the settings item from the gear menu to the Application |
234 |
void _cb_show_settings (GSimpleAction * action, GVariant * parameter, |
235 |
gpointer user_data) { |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
236 |
GPumpApp * self = GPUMP_APP (user_data); |
|
20
by Gustav Hatvigsson
* Added a singeltonian class to keep settings data in. |
237 |
GPumpSettings * settings = gpump_settings_new (self->priv->window); |
238 |
gpump_settings_show (settings); |
|
|
14
by Gustav Hartvigsson
* Started work on the settings dioloug. |
239 |
}
|
|
1
by Gustav Hartvigsson
Initial code. |
240 |
|
|
16
by Gustav Hatvigsson
* Moved the settings item from the gear menu to the Application |
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 |