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" |
|
7 |
||
|
6
by Gustav Hartvigsson
There we go. |
8 |
#define GPUMP_APP_GET_PRIVATE(obj)\
|
9 |
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GPUMP_TYPE_APP, GPumpAppPrivate))
|
|
|
1
by Gustav Hartvigsson
Initial code. |
10 |
|
11 |
G_DEFINE_TYPE (GPumpApp, gpump_app, GTK_TYPE_APPLICATION) |
|
12 |
||
13 |
struct GPumpAppPrivate { |
|
14 |
|
|
15 |
GSettings * ui_settings; |
|
16 |
GSettings * login_settings; |
|
17 |
|
|
18 |
/* Widgets */ |
|
19 |
GtkWidget * window; |
|
20 |
GtkWidget * header_bar; |
|
21 |
GtkWidget * layout; /* GtkBox */ |
|
22 |
GtkWidget * post_list_view; /* GtkTreeView */ |
|
|
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; |
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
25 |
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
26 |
/* gear menu */ |
27 |
GtkWidget * gear_menu; /* GtkMenu */ |
|
28 |
|
|
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
29 |
/* List store */ |
|
1
by Gustav Hartvigsson
Initial code. |
30 |
GtkListStore * post_list_store; |
31 |
};
|
|
32 |
||
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
33 |
typedef enum { |
34 |
GPUPM_APP_MAIN_LIST_COL = 0, |
|
35 |
GPUMP_APP_MAIN_LIST_NUM_COL |
|
36 |
} GPumpAppCols; |
|
37 |
||
38 |
||
39 |
||
|
1
by Gustav Hartvigsson
Initial code. |
40 |
/* * Callback and private function declarations *******************************/
|
41 |
void gpump_app_class_init (GPumpAppClass * klass); |
|
42 |
void gpump_app_activate (GApplication * application); |
|
43 |
void gpump_app_init (GPumpApp * self); |
|
44 |
||
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
45 |
void _prepere_window (GPumpApp * self); |
46 |
void _prepere_gear_menu (GPumpApp * self); |
|
47 |
void _prepere_new_post_button (GPumpApp * self); |
|
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
48 |
|
|
1
by Gustav Hartvigsson
Initial code. |
49 |
/* * Class functions **********************************************************/
|
50 |
GPumpApp * gpump_app_new (void) { |
|
51 |
GPumpApp * self = g_object_new (GPUMP_TYPE_APP, |
|
52 |
"application-id", "org.gego.gpump", |
|
53 |
"flags",G_APPLICATION_FLAGS_NONE, |
|
54 |
NULL); |
|
55 |
return self; |
|
56 |
}
|
|
57 |
||
58 |
void gpump_app_init (GPumpApp * self) { |
|
|
5
by Gustav Hartvigsson
Nope... Did not fix it... |
59 |
g_print ("init\n"); |
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
60 |
self->priv = GPUMP_APP_GET_PRIVATE (self); |
|
5
by Gustav Hartvigsson
Nope... Did not fix it... |
61 |
|
|
1
by Gustav Hartvigsson
Initial code. |
62 |
}
|
63 |
||
64 |
void gpump_app_class_init (GPumpAppClass * klass) { |
|
65 |
g_print("GPumpApp class init.\n"); |
|
66 |
|
|
67 |
// GObject * object_class = G_OBJECT_CLASS (klass); |
|
68 |
GApplicationClass * application_class = G_APPLICATION_CLASS (klass); |
|
69 |
|
|
70 |
application_class->activate = gpump_app_activate; |
|
71 |
|
|
|
6
by Gustav Hartvigsson
There we go. |
72 |
g_type_class_add_private (klass, sizeof(GPumpAppPrivate)); |
|
1
by Gustav Hartvigsson
Initial code. |
73 |
|
74 |
g_print ("GPumpApp class init done.\n"); |
|
75 |
}
|
|
76 |
||
77 |
||
78 |
void gpump_app_activate (GApplication * application) { |
|
79 |
g_print ("GPumpApp activate.\n"); |
|
80 |
|
|
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
81 |
/* Creating widgets */ |
|
8
by Gustav Hartvigsson
moved the UI building to its own private function |
82 |
|
83 |
|
|
84 |
|
|
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
85 |
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
86 |
/* Prepere stuff */ |
|
8
by Gustav Hartvigsson
moved the UI building to its own private function |
87 |
_prepere_window (GPUMP_APP (application)); |
88 |
_prepere_gear_menu (GPUMP_APP (application)); |
|
89 |
_prepere_new_post_button (GPUMP_APP (application)); |
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
90 |
|
|
3
by Gustav Hartvigsson
Something is wrong with GtkListStore it seems, |
91 |
/* Show it! */ |
|
8
by Gustav Hartvigsson
moved the UI building to its own private function |
92 |
gtk_widget_show_all (GTK_WIDGET(GPUMP_APP(application)->priv->window)); |
|
1
by Gustav Hartvigsson
Initial code. |
93 |
|
94 |
g_print ("done GPumpApp activate.\n"); |
|
95 |
}
|
|
96 |
||
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
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 |
||
120 |
void _prepere_new_post_button (GPumpApp * self) { |
|
121 |
GPumpAppPrivate * priv = self->priv; |
|
122 |
|
|
123 |
GtkWidget * share_icon = gtk_image_new_from_icon_name ("text-editor-symbolic", |
|
124 |
GTK_ICON_SIZE_LARGE_TOOLBAR); |
|
125 |
priv->btn_new_post = gtk_button_new (); |
|
126 |
gtk_button_set_image (GTK_BUTTON (priv->btn_new_post), share_icon); |
|
127 |
|
|
128 |
gtk_header_bar_pack_start (GTK_HEADER_BAR (priv->header_bar), |
|
129 |
priv->btn_new_post); |
|
130 |
}
|
|
131 |
||
132 |
void _prepere_window (GPumpApp * self) { |
|
|
8
by Gustav Hartvigsson
moved the UI building to its own private function |
133 |
GPumpAppPrivate * priv = self->priv; |
134 |
GtkWidget * window = priv->window = |
|
135 |
gtk_application_window_new (GTK_APPLICATION (self)); |
|
136 |
GtkWidget * header_bar = priv->header_bar = gtk_header_bar_new (); |
|
137 |
GtkWidget * layout = priv->layout = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); |
|
138 |
|
|
139 |
gtk_header_bar_set_title (GTK_HEADER_BAR (header_bar), "GPump"); |
|
140 |
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), TRUE); |
|
141 |
|
|
142 |
|
|
143 |
GtkListStore * post_list_store = priv->post_list_store = |
|
144 |
gtk_list_store_new ( GPUMP_APP_MAIN_LIST_NUM_COL, GTK_TYPE_WIDGET); |
|
145 |
|
|
146 |
GtkWidget * post_list_view = priv->post_list_view = |
|
147 |
gtk_tree_view_new (); |
|
148 |
|
|
149 |
/* test, |
|
150 |
* This does not render, becouse you can only render GtkCellRenderers..
|
|
151 |
*/
|
|
152 |
GtkWidget * test_widget = gtk_button_new_with_label |
|
153 |
("Test test test!\n moar tests!"); |
|
154 |
gtk_widget_show (GTK_WIDGET(test_widget)); |
|
155 |
GtkTreeIter iter; |
|
156 |
gtk_list_store_append (post_list_store, &iter); |
|
157 |
gtk_list_store_set (post_list_store, &iter, GPUPM_APP_MAIN_LIST_COL, |
|
158 |
test_widget, -1); |
|
159 |
gtk_list_store_append (post_list_store, &iter); |
|
160 |
|
|
161 |
gtk_tree_view_set_model (GTK_TREE_VIEW (post_list_view), |
|
162 |
GTK_TREE_MODEL(post_list_store)); |
|
163 |
|
|
164 |
/* adding widgets */ |
|
165 |
gtk_window_set_titlebar (GTK_WINDOW (window), header_bar); |
|
166 |
gtk_widget_set_size_request (window, 500,500); |
|
167 |
|
|
168 |
gtk_box_pack_start (GTK_BOX (layout), post_list_view, TRUE, TRUE, 1); |
|
169 |
|
|
170 |
gtk_container_add (GTK_CONTAINER (window), layout); |
|
|
7
by Gustav Hartvigsson
The UI is starting to take shape. |
171 |
}
|
|
1
by Gustav Hartvigsson
Initial code. |
172 |
|
173 |
/* * Callback implemenations **************************************************/
|
|
174 |