Changeset 347
- Timestamp:
- 05/18/06 20:41:23
- Files:
-
- trunk/libtinymail-gnome-desktop/tny-platform-factory.c (modified) (2 diffs)
- trunk/libtinymailui-gtk/Makefile.am (modified) (2 diffs)
- trunk/libtinymailui-gtk/tny-msg-view.c (modified) (8 diffs)
- trunk/libtinymailui-gtk/tny-msg-view.h (modified) (2 diffs)
- trunk/libtinymailui-gtk/tny-save-strategy.c (added)
- trunk/libtinymailui-gtk/tny-save-strategy.h (added)
- trunk/libtinymailui-mozembed/tny-moz-embed-msg-view.c (modified) (8 diffs)
- trunk/libtinymailui-mozembed/tny-moz-embed-msg-view.h (modified) (2 diffs)
- trunk/libtinymailui/Makefile.am (modified) (2 diffs)
- trunk/libtinymailui/tny-msg-view-iface.c (modified) (1 diff)
- trunk/libtinymailui/tny-msg-view-iface.h (modified) (2 diffs)
- trunk/libtinymailui/tny-save-strategy-iface.c (added)
- trunk/libtinymailui/tny-save-strategy-iface.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libtinymail-gnome-desktop/tny-platform-factory.c
r335 r347 19 19 20 20 #include <tny-platform-factory.h> 21 22 #include <tny-save-strategy-iface.h> 23 #include <tny-save-strategy.h> 21 24 22 25 #include <tny-account-store-iface.h> … … 58 61 tny_platform_factory_new_msg_view (TnyPlatformFactoryIface *self) 59 62 { 63 TnySaveStrategyIface *save_strategy = TNY_SAVE_STRATEGY_IFACE ( 64 tny_save_strategy_new ()); 65 60 66 #ifdef MOZEMBED 61 return TNY_MSG_VIEW_IFACE (tny_moz_embed_msg_view_new ( ));67 return TNY_MSG_VIEW_IFACE (tny_moz_embed_msg_view_new (save_strategy)); 62 68 #else 63 return TNY_MSG_VIEW_IFACE (tny_msg_view_new ( ));69 return TNY_MSG_VIEW_IFACE (tny_msg_view_new (save_strategy)); 64 70 #endif 65 71 } trunk/libtinymailui-gtk/Makefile.am
r340 r347 11 11 12 12 libtinymailui_gtk_1_0_headers = \ 13 tny-save-strategy.h \ 13 14 tny-msg-view.h \ 14 15 tny-msg-window.h \ … … 20 21 libtinymailui_gtk_1_0_la_SOURCES = \ 21 22 $(libtinymailui_gtk_1_0_headers)\ 23 tny-save-strategy.c \ 22 24 tny-msg-view.c \ 23 25 tny-msg-window.c \ trunk/libtinymailui-gtk/tny-msg-view.c
r343 r347 51 51 GtkIconView *attachview; 52 52 GtkWidget *attachview_sw; 53 TnySaveStrategyIface *save_strategy; 53 54 }; 54 55 … … 153 154 } 154 155 155 /* TODO: Improve this (refactoring) */ 156 157 #ifdef GNOME 158 static GnomeVFSResult 159 save_to_file (const gchar *uri, TnyMsgMimePartIface *part) 160 { 161 GnomeVFSResult result; 162 GnomeVFSHandle *handle; 163 TnyVfsStream *stream = NULL; 164 165 result = gnome_vfs_create (&handle, uri, 166 GNOME_VFS_OPEN_WRITE, FALSE, 0777); 167 168 if (G_UNLIKELY (result != GNOME_VFS_OK)) 169 return result; 170 171 stream = tny_vfs_stream_new (handle); 172 tny_msg_mime_part_iface_decode_to_stream (part, TNY_STREAM_IFACE (stream)); 173 174 /* This also closes the gnome-vfs handle (maybe it shouldn't?) */ 175 g_object_unref (G_OBJECT (stream)); 176 177 return result; 178 } 179 #else 180 static void 181 save_to_file (const gchar *uri, TnyMsgMimePartIface *part) 182 { 183 /* "file:///filename" */ 184 /* 1234567^ */ 185 186 /* TODO: make this platform independent */ 187 const gchar *local_filename = uri+7; 188 int fd = open (local_filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 189 190 if (fd) 191 { 192 TnyFsStream *stream = NULL; 193 stream = tny_fs_stream_new (fd); 194 tny_msg_mime_part_iface_decode_to_stream (part, TNY_STREAM_IFACE (stream)); 195 196 /* This also closes the file descriptor (maybe it shouldn't?) */ 197 g_object_unref (G_OBJECT (stream)); 198 } 199 200 return; 201 } 202 #endif 156 void 157 tny_msg_view_set_save_strategy (TnyMsgViewIface *self, TnySaveStrategyIface *strategy) 158 { 159 TnyMsgViewPriv *priv = TNY_MSG_VIEW_GET_PRIVATE (self); 160 161 if (priv->save_strategy) 162 g_object_unref (G_OBJECT (priv->save_strategy)); 163 164 g_object_ref (G_OBJECT (strategy)); 165 priv->save_strategy = strategy; 166 167 return; 168 } 169 203 170 204 171 static void … … 209 176 GtkTreeModel *model = gtk_icon_view_get_model (icon_view); 210 177 GtkTreeIter iter; 178 179 if (!G_LIKELY (priv->save_strategy)) 180 { 181 g_warning ("No save strategy for this message view\n"); 182 return; 183 } 211 184 212 185 if (G_LIKELY (gtk_tree_model_get_iter(model, &iter, path))) … … 219 192 220 193 if (G_LIKELY (part)) 221 { 222 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); 223 224 if (G_UNLIKELY (!GTK_WIDGET_TOPLEVEL (toplevel))) 225 return; 226 227 GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG 228 (gtk_file_chooser_dialog_new ("Save File", 229 GTK_WINDOW (toplevel), 230 GTK_FILE_CHOOSER_ACTION_SAVE, 231 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, 232 GTK_RESPONSE_ACCEPT, NULL)); 233 234 gtk_file_chooser_set_do_overwrite_confirmation 235 (GTK_FILE_CHOOSER (dialog), TRUE); 236 237 gtk_file_chooser_set_current_folder 238 (GTK_FILE_CHOOSER (dialog), g_get_home_dir ()); 239 240 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), 241 tny_msg_mime_part_iface_get_filename (part)); 242 243 if (G_LIKELY (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)) 244 { 245 gchar *uri; 246 247 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); 248 249 if (uri) 250 { 251 save_to_file (uri, part); 252 g_free (uri); 253 } 254 } 255 256 gtk_widget_destroy (GTK_WIDGET (dialog)); 257 } 194 tny_save_strategy_iface_save (priv->save_strategy, part); 195 258 196 } 259 197 … … 322 260 /** 323 261 * tny_msg_view_new: 324 * 262 * @save_strategy: The save strategy to use 325 263 * 326 264 * Return value: a new #TnyMsgViewIface instance implemented for Gtk+ 327 265 **/ 328 266 TnyMsgView* 329 tny_msg_view_new ( void)267 tny_msg_view_new (TnySaveStrategyIface *save_strategy) 330 268 { 331 269 TnyMsgView *self = g_object_new (TNY_TYPE_MSG_VIEW, NULL); 270 271 tny_msg_view_iface_set_save_strategy (TNY_MSG_VIEW_IFACE (self), save_strategy); 332 272 333 273 return self; … … 343 283 GtkWidget *mitem = gtk_menu_item_new_with_mnemonic ("Save _As"); 344 284 GtkTextBuffer *headerbuffer; 285 286 priv->save_strategy = NULL; 345 287 346 288 gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (self), NULL); … … 421 363 g_object_unref (G_OBJECT (priv->msg)); 422 364 365 if (G_LIKELY (priv->save_strategy)) 366 g_object_unref (G_OBJECT (priv->save_strategy)); 367 423 368 (*parent_class->finalize) (object); 424 369 … … 432 377 433 378 klass->set_msg_func = tny_msg_view_set_msg; 379 klass->set_save_strategy_func = tny_msg_view_set_save_strategy; 434 380 435 381 return; trunk/libtinymailui-gtk/tny-msg-view.h
r139 r347 29 29 #include <tny-stream-iface.h> 30 30 #include <tny-msg-mime-part-iface.h> 31 #include <tny-save-strategy-iface.h> 31 32 32 33 G_BEGIN_DECLS … … 54 55 55 56 GType tny_msg_view_get_type (void); 56 TnyMsgView* tny_msg_view_new ( void);57 TnyMsgView* tny_msg_view_new (TnySaveStrategyIface *save_strategy); 57 58 58 59 G_END_DECLS trunk/libtinymailui-mozembed/tny-moz-embed-msg-view.c
r343 r347 53 53 GtkIconView *attachview; 54 54 GtkWidget *attachview_sw; 55 TnySaveStrategyIface *save_strategy; 55 56 }; 56 57 … … 208 209 return; 209 210 } 210 /* TODO: Improve this (refactor) */ 211 #ifdef GNOME 212 static GnomeVFSResult 213 save_to_file (const gchar *uri, TnyMsgMimePartIface *part) 214 { 215 GnomeVFSResult result; 216 GnomeVFSHandle *handle; 217 TnyVfsStream *stream = NULL; 218 219 result = gnome_vfs_create (&handle, uri, 220 GNOME_VFS_OPEN_WRITE, FALSE, 0777); 221 222 if (G_UNLIKELY (result != GNOME_VFS_OK)) 223 return result; 224 225 stream = tny_vfs_stream_new (handle); 226 227 /* TODO: Add a filter (decoder) here (depends on encoding) */ 228 tny_msg_mime_part_iface_decode_to_stream (part, TNY_STREAM_IFACE (stream)); 229 230 /* This also closes the gnome-vfs handle (maybe it shouldn't?) */ 231 g_object_unref (G_OBJECT (stream)); 232 233 return result; 234 } 235 #else 236 static void 237 save_to_file (const gchar *uri, TnyMsgMimePartIface *part) 238 { 239 /* "file:///filename" */ 240 /* 1234567^ */ 241 242 /* TODO: make this platform independent */ 243 const gchar *local_filename = uri+7; 244 int fd = open (local_filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 245 246 if (fd) 247 { 248 TnyFsStream *stream = NULL; 249 stream = tny_fs_stream_new (fd); 250 tny_msg_mime_part_iface_decode_to_stream (part, TNY_STREAM_IFACE (stream)); 251 252 /* This also closes the file descriptor (maybe it shouldn't?) */ 253 g_object_unref (G_OBJECT (stream)); 254 } 255 256 return; 257 } 258 #endif 211 212 213 void 214 tny_mozembed_msg_view_set_save_strategy (TnyMsgViewIface *self, TnySaveStrategyIface *strategy) 215 { 216 TnyMozEmbedMsgViewPriv *priv = TNY_MOZ_EMBED_MSG_VIEW_GET_PRIVATE (self); 217 218 if (priv->save_strategy) 219 g_object_unref (G_OBJECT (priv->save_strategy)); 220 221 g_object_ref (G_OBJECT (strategy)); 222 priv->save_strategy = strategy; 223 224 return; 225 } 226 259 227 260 228 static void … … 265 233 GtkTreeModel *model = gtk_icon_view_get_model (icon_view); 266 234 GtkTreeIter iter; 235 236 if (!G_LIKELY (priv->save_strategy)) 237 { 238 g_warning ("No save strategy for this message view\n"); 239 return; 240 } 267 241 268 242 if (G_LIKELY (gtk_tree_model_get_iter (model, &iter, path))) … … 275 249 276 250 if (G_LIKELY (part)) 277 { 278 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); 279 280 if (G_UNLIKELY (!GTK_WIDGET_TOPLEVEL (toplevel))) 281 return; 282 283 GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG 284 (gtk_file_chooser_dialog_new ("Save File", 285 GTK_WINDOW (toplevel), 286 GTK_FILE_CHOOSER_ACTION_SAVE, 287 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, 288 GTK_RESPONSE_ACCEPT, NULL)); 289 290 gtk_file_chooser_set_do_overwrite_confirmation 291 (GTK_FILE_CHOOSER (dialog), TRUE); 292 293 gtk_file_chooser_set_current_folder 294 (GTK_FILE_CHOOSER (dialog), g_get_home_dir ()); 295 296 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), 297 tny_msg_mime_part_iface_get_filename (part)); 298 299 if (G_LIKELY (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)) 300 { 301 gchar *uri; 302 303 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); 304 305 if (uri) 306 { 307 save_to_file (uri, part); 308 g_free (uri); 309 } 310 } 311 312 gtk_widget_destroy (GTK_WIDGET (dialog)); 313 } 251 tny_save_strategy_iface_save (priv->save_strategy, part); 314 252 } 315 253 … … 378 316 /** 379 317 * tny_mozembed_msg_view_new: 380 * 318 * @save_strategy: The save strategy to use 381 319 * 382 320 * Return value: a new #TnyMsgViewIface instance implemented for Gtk+ 383 321 **/ 384 322 TnyMozEmbedMsgView* 385 tny_moz_embed_msg_view_new ( void)323 tny_moz_embed_msg_view_new (TnySaveStrategyIface *save_strategy) 386 324 { 387 325 TnyMozEmbedMsgView *self = g_object_new (TNY_TYPE_MOZ_EMBED_MSG_VIEW, NULL); 326 327 tny_msg_view_iface_set_save_strategy (TNY_MSG_VIEW_IFACE (self), save_strategy); 388 328 389 329 return self; … … 399 339 GtkWidget *mitem = gtk_menu_item_new_with_mnemonic ("Save _As"); 400 340 GtkTextBuffer *headerbuffer; 341 342 priv->save_strategy = NULL; 401 343 402 344 gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (self), NULL); … … 483 425 g_object_unref (G_OBJECT (priv->msg)); 484 426 427 if (G_LIKELY (priv->save_strategy)) 428 g_object_unref (G_OBJECT (priv->save_strategy)); 429 485 430 (*parent_class->finalize) (object); 486 431 … … 494 439 495 440 klass->set_msg_func = tny_moz_embed_msg_view_set_msg; 441 klass->set_save_strategy_func = tny_mozembed_msg_view_set_save_strategy; 496 442 497 443 return; trunk/libtinymailui-mozembed/tny-moz-embed-msg-view.h
r335 r347 29 29 #include <tny-stream-iface.h> 30 30 #include <tny-msg-mime-part-iface.h> 31 #include <tny-save-strategy-iface.h> 31 32 32 33 G_BEGIN_DECLS … … 54 55 55 56 GType tny_moz_embed_msg_view_get_type (void); 56 TnyMozEmbedMsgView* tny_moz_embed_msg_view_new ( void);57 TnyMozEmbedMsgView* tny_moz_embed_msg_view_new (TnySaveStrategyIface *save_strategy); 57 58 58 59 G_END_DECLS trunk/libtinymailui/Makefile.am
r340 r347 8 8 tny-summary-window-iface.h \ 9 9 tny-msg-view-iface.h \ 10 tny-save-strategy-iface.h \ 10 11 tny-msg-window-iface.h \ 11 12 tny-platform-factory-iface.h … … 14 15 $(libtinymailui_1_0_headers) \ 15 16 tny-summary-window-iface.c \ 17 tny-save-strategy-iface.c \ 16 18 tny-msg-view-iface.c \ 17 19 tny-msg-window-iface.c \ trunk/libtinymailui/tny-msg-view-iface.c
r212 r347 19 19 20 20 #include <tny-msg-view-iface.h> 21 22 /** 23 * tny_msg_view_iface_set_save_strategy: 24 * @self: A #TnyMsgViewIface instance 25 * @strategy: A TnySaveStrategyIface instace 26 * 27 * Set the strategy used for saving mime-parts 28 * 29 **/ 30 void 31 tny_msg_view_iface_set_save_strategy (TnyMsgViewIface *self, TnySaveStrategyIface *strategy) 32 { 33 TNY_MSG_VIEW_IFACE_GET_CLASS (self)->set_save_strategy_func (self, strategy); 34 return; 35 } 36 21 37 22 38 /** trunk/libtinymailui/tny-msg-view-iface.h
r139 r347 25 25 #include <tny-shared.h> 26 26 27 #include <tny-save-strategy-iface.h> 28 27 29 G_BEGIN_DECLS 28 30 … … 42 44 GTypeInterface parent; 43 45 44 void (*set_msg_func) (TnyMsgViewIface *self, TnyMsgIface *msg); 46 void (*set_msg_func) (TnyMsgViewIface *self, TnyMsgIface *msg); 47 void (*set_save_strategy_func) (TnyMsgViewIface *self, TnySaveStrategyIface *strategy); 45 48 }; 46 49 47 GType tny_msg_view_iface_get_type(void);50 GType tny_msg_view_iface_get_type (void); 48 51 49 void tny_msg_view_iface_set_msg (TnyMsgViewIface *self, TnyMsgIface *msg); 52 void tny_msg_view_iface_set_msg (TnyMsgViewIface *self, TnyMsgIface *msg); 53 void tny_msg_view_iface_set_save_strategy (TnyMsgViewIface *self, TnySaveStrategyIface *strategy); 50 54 51 55
