diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-02-22 18:37:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-02-22 18:37:01 +0000 |
commit | 6b79c1cb1cabce80e6aba519f79ea51b0e4e185d (patch) | |
tree | c57db526f01772779f86e7235f342f51685fa257 | |
parent | 7fd339523022aa439cdfa3203399606b30c63419 (diff) | |
download | gnunet-gtk-6b79c1cb1cabce80e6aba519f79ea51b0e4e185d.tar.gz gnunet-gtk-6b79c1cb1cabce80e6aba519f79ea51b0e4e185d.zip |
LRN: Save-and-restore-window-position-and-size
-rw-r--r-- | src/fs/gnunet-fs-gtk.c | 107 |
1 files changed, 104 insertions, 3 deletions
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c index c031a19f..8f4457a0 100644 --- a/src/fs/gnunet-fs-gtk.c +++ b/src/fs/gnunet-fs-gtk.c | |||
@@ -93,6 +93,55 @@ GNUNET_FS_GTK_get_anonymity_level_list_store () | |||
93 | 93 | ||
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Obtains main window position and size before it's destroyed | ||
97 | * and saves these into user's config file. | ||
98 | * | ||
99 | * @param main_window main window widget | ||
100 | */ | ||
101 | static void | ||
102 | main_window_save_position (GtkWidget *main_window) | ||
103 | { | ||
104 | GdkWindow *main_window_gdk; | ||
105 | |||
106 | gint window_x, window_y, window_width, window_height, maximized; | ||
107 | GdkWindowState window_state; | ||
108 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
109 | struct GNUNET_CONFIGURATION_Handle *cfgDefault; | ||
110 | cfgDefault = GNUNET_CONFIGURATION_create (); | ||
111 | (void) GNUNET_CONFIGURATION_load (cfgDefault, NULL); /* load defaults only */ | ||
112 | |||
113 | /* FIXME: is it safe to discard const qualifier? */ | ||
114 | cfg = (struct GNUNET_CONFIGURATION_Handle *) | ||
115 | GNUNET_GTK_main_loop_get_configuration (ml); | ||
116 | |||
117 | main_window_gdk = gtk_widget_get_window (main_window); | ||
118 | maximized = GNUNET_YES; | ||
119 | if (NULL != main_window_gdk) | ||
120 | { | ||
121 | window_state = gdk_window_get_state (main_window_gdk); | ||
122 | if (!(window_state & GDK_WINDOW_STATE_MAXIMIZED)) | ||
123 | maximized = GNUNET_NO; | ||
124 | } | ||
125 | |||
126 | gtk_window_get_position (GTK_WINDOW (main_window), &window_x, &window_y); | ||
127 | gtk_window_get_size (GTK_WINDOW (main_window), &window_width, &window_height); | ||
128 | |||
129 | GNUNET_CONFIGURATION_set_value_number (cfg, "gnunet-gtk", | ||
130 | "MAIN_WINDOW_X", window_x); | ||
131 | GNUNET_CONFIGURATION_set_value_number (cfg, "gnunet-gtk", | ||
132 | "MAIN_WINDOW_Y", window_y); | ||
133 | GNUNET_CONFIGURATION_set_value_number (cfg, "gnunet-gtk", | ||
134 | "MAIN_WINDOW_WIDTH", window_width); | ||
135 | GNUNET_CONFIGURATION_set_value_number (cfg, "gnunet-gtk", | ||
136 | "MAIN_WINDOW_HEIGHT", window_height); | ||
137 | GNUNET_CONFIGURATION_set_value_string (cfg, "gnunet-gtk", | ||
138 | "MAIN_WINDOW_MAXIMIZED", maximized == GNUNET_YES ? "YES" : "NO"); | ||
139 | |||
140 | GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, "~/.gnunet/gnunet.conf"); | ||
141 | GNUNET_CONFIGURATION_destroy (cfgDefault); | ||
142 | } | ||
143 | |||
144 | /** | ||
96 | * Task run on shutdown. | 145 | * Task run on shutdown. |
97 | * FIXME-STYLE: does this need to be a separate task!? | 146 | * FIXME-STYLE: does this need to be a separate task!? |
98 | * | 147 | * |
@@ -120,6 +169,10 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
120 | void | 169 | void |
121 | GNUNET_GTK_quit_cb (GObject * object, gpointer user_data) | 170 | GNUNET_GTK_quit_cb (GObject * object, gpointer user_data) |
122 | { | 171 | { |
172 | GtkWidget *main_window = GTK_WIDGET (object); | ||
173 | |||
174 | main_window_save_position (main_window); | ||
175 | |||
123 | GNUNET_GTK_tray_icon_destroy (); | 176 | GNUNET_GTK_tray_icon_destroy (); |
124 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 177 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
125 | &shutdown_task, NULL); | 178 | &shutdown_task, NULL); |
@@ -138,6 +191,10 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
138 | { | 191 | { |
139 | GtkWidget *main_window; | 192 | GtkWidget *main_window; |
140 | GtkTreeView *metadata_tree; | 193 | GtkTreeView *metadata_tree; |
194 | unsigned long long dl_parallel, req_parallel, window_x, window_y, | ||
195 | window_width, window_height; | ||
196 | int maximized; | ||
197 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
141 | 198 | ||
142 | ml = cls; | 199 | ml = cls; |
143 | 200 | ||
@@ -148,7 +205,37 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
148 | main_window = | 205 | main_window = |
149 | GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object | 206 | GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object |
150 | ("GNUNET_GTK_main_window")); | 207 | ("GNUNET_GTK_main_window")); |
151 | gtk_window_maximize (GTK_WINDOW (main_window)); | 208 | |
209 | cfg = GNUNET_GTK_main_loop_get_configuration (ml); | ||
210 | |||
211 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", | ||
212 | "MAIN_WINDOW_X", &window_x)) | ||
213 | window_x = ULONG_MAX; | ||
214 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", | ||
215 | "MAIN_WINDOW_Y", &window_y)) | ||
216 | window_y = ULONG_MAX; | ||
217 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", | ||
218 | "MAIN_WINDOW_WIDTH", &window_width)) | ||
219 | window_width = ULONG_MAX; | ||
220 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", | ||
221 | "MAIN_WINDOW_HEIGHT", &window_height)) | ||
222 | window_height = ULONG_MAX; | ||
223 | if (GNUNET_SYSERR == (maximized = GNUNET_CONFIGURATION_get_value_yesno (cfg, | ||
224 | "gnunet-gtk", "MAIN_WINDOW_MAXIMIZED"))) | ||
225 | maximized = GNUNET_YES; | ||
226 | |||
227 | if (window_x == ULONG_MAX || window_y == ULONG_MAX || | ||
228 | window_width == ULONG_MAX || window_height == ULONG_MAX || | ||
229 | maximized == GNUNET_YES) | ||
230 | { | ||
231 | /* If anything is wrong - play safe and show it maximized */ | ||
232 | gtk_window_maximize (GTK_WINDOW (main_window)); | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | gtk_window_move (GTK_WINDOW (main_window), window_x, window_y); | ||
237 | gtk_window_resize (GTK_WINDOW (main_window), window_width, window_height); | ||
238 | } | ||
152 | 239 | ||
153 | /* Allow multiple selection in metadata view; */ | 240 | /* Allow multiple selection in metadata view; */ |
154 | /* FIXME-GTK3: this can be done within (modern versions of) glade */ | 241 | /* FIXME-GTK3: this can be done within (modern versions of) glade */ |
@@ -161,12 +248,26 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
161 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), | 248 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), |
162 | "gnunet-fs-gtk", | 249 | "gnunet-fs-gtk", |
163 | "gnunet-fs-gtk"); | 250 | "gnunet-fs-gtk"); |
251 | |||
252 | /* FIXME: should these '1's be here? Maybe better to put them into | ||
253 | * default config files? | ||
254 | */ | ||
255 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", | ||
256 | "MAX_PARALLEL_DOWNLOADS", &dl_parallel)) | ||
257 | dl_parallel = 1; | ||
258 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", | ||
259 | "MAX_PARALLEL_REQUESTS", &req_parallel)) | ||
260 | req_parallel = 1; | ||
261 | |||
164 | /* initialize file-sharing */ | 262 | /* initialize file-sharing */ |
165 | fs = GNUNET_FS_start (GNUNET_GTK_main_loop_get_configuration (ml), | 263 | fs = GNUNET_FS_start (cfg, "gnunet-fs-gtk", |
166 | "gnunet-fs-gtk", | ||
167 | &GNUNET_GTK_fs_event_handler, NULL, | 264 | &GNUNET_GTK_fs_event_handler, NULL, |
168 | GNUNET_FS_FLAGS_NONE | GNUNET_FS_FLAGS_PERSISTENCE | 265 | GNUNET_FS_FLAGS_NONE | GNUNET_FS_FLAGS_PERSISTENCE |
169 | /* | GNUNET_FS_FLAGS_DO_PROBES */ , | 266 | /* | GNUNET_FS_FLAGS_DO_PROBES */ , |
267 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, | ||
268 | (unsigned int) dl_parallel, | ||
269 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, | ||
270 | (unsigned int) req_parallel, | ||
170 | GNUNET_FS_OPTIONS_END); | 271 | GNUNET_FS_OPTIONS_END); |
171 | if (NULL == fs) | 272 | if (NULL == fs) |
172 | { | 273 | { |