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