Changeset 347

Show
Ignore:
Timestamp:
05/18/06 20:41:23
Author:
pvanhoof
Message:

save strategy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymail-gnome-desktop/tny-platform-factory.c

    r335 r347  
    1919 
    2020#include <tny-platform-factory.h> 
     21 
     22#include <tny-save-strategy-iface.h> 
     23#include <tny-save-strategy.h> 
    2124 
    2225#include <tny-account-store-iface.h> 
     
    5861tny_platform_factory_new_msg_view (TnyPlatformFactoryIface *self) 
    5962{ 
     63        TnySaveStrategyIface *save_strategy = TNY_SAVE_STRATEGY_IFACE ( 
     64                tny_save_strategy_new ()); 
     65 
    6066#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)); 
    6268#else 
    63         return TNY_MSG_VIEW_IFACE (tny_msg_view_new ()); 
     69        return TNY_MSG_VIEW_IFACE (tny_msg_view_new (save_strategy)); 
    6470#endif 
    6571} 
  • trunk/libtinymailui-gtk/Makefile.am

    r340 r347  
    1111 
    1212libtinymailui_gtk_1_0_headers =         \ 
     13        tny-save-strategy.h             \ 
    1314        tny-msg-view.h                  \ 
    1415        tny-msg-window.h                \ 
     
    2021libtinymailui_gtk_1_0_la_SOURCES =      \ 
    2122        $(libtinymailui_gtk_1_0_headers)\ 
     23        tny-save-strategy.c             \ 
    2224        tny-msg-view.c                  \ 
    2325        tny-msg-window.c                \ 
  • trunk/libtinymailui-gtk/tny-msg-view.c

    r343 r347  
    5151        GtkIconView *attachview; 
    5252        GtkWidget *attachview_sw; 
     53        TnySaveStrategyIface *save_strategy; 
    5354}; 
    5455 
     
    153154} 
    154155 
    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 
     156void 
     157tny_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 
    203170 
    204171static void 
     
    209176        GtkTreeModel *model = gtk_icon_view_get_model (icon_view); 
    210177        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        } 
    211184 
    212185        if (G_LIKELY (gtk_tree_model_get_iter(model, &iter, path))) 
     
    219192 
    220193                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 
    258196        } 
    259197 
     
    322260/** 
    323261 * tny_msg_view_new: 
    324  * 
     262 * @save_strategy: The save strategy to use 
    325263 * 
    326264 * Return value: a new #TnyMsgViewIface instance implemented for Gtk+ 
    327265 **/ 
    328266TnyMsgView* 
    329 tny_msg_view_new (void
     267tny_msg_view_new (TnySaveStrategyIface *save_strategy
    330268{ 
    331269        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); 
    332272 
    333273        return self; 
     
    343283        GtkWidget *mitem = gtk_menu_item_new_with_mnemonic ("Save _As"); 
    344284        GtkTextBuffer *headerbuffer; 
     285 
     286        priv->save_strategy = NULL; 
    345287 
    346288        gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (self), NULL); 
     
    421363                g_object_unref (G_OBJECT (priv->msg)); 
    422364 
     365        if (G_LIKELY (priv->save_strategy)) 
     366                g_object_unref (G_OBJECT (priv->save_strategy)); 
     367 
    423368        (*parent_class->finalize) (object); 
    424369 
     
    432377 
    433378        klass->set_msg_func = tny_msg_view_set_msg; 
     379        klass->set_save_strategy_func = tny_msg_view_set_save_strategy; 
    434380 
    435381        return; 
  • trunk/libtinymailui-gtk/tny-msg-view.h

    r139 r347  
    2929#include <tny-stream-iface.h> 
    3030#include <tny-msg-mime-part-iface.h> 
     31#include <tny-save-strategy-iface.h> 
    3132 
    3233G_BEGIN_DECLS 
     
    5455 
    5556GType               tny_msg_view_get_type       (void); 
    56 TnyMsgView*         tny_msg_view_new            (void); 
     57TnyMsgView*         tny_msg_view_new            (TnySaveStrategyIface *save_strategy); 
    5758 
    5859G_END_DECLS 
  • trunk/libtinymailui-mozembed/tny-moz-embed-msg-view.c

    r343 r347  
    5353        GtkIconView *attachview; 
    5454        GtkWidget *attachview_sw; 
     55        TnySaveStrategyIface *save_strategy; 
    5556}; 
    5657 
     
    208209        return; 
    209210} 
    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 
     213void 
     214tny_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 
    259227 
    260228static void 
     
    265233        GtkTreeModel *model = gtk_icon_view_get_model (icon_view); 
    266234        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        } 
    267241 
    268242        if (G_LIKELY (gtk_tree_model_get_iter (model, &iter, path))) 
     
    275249 
    276250                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); 
    314252        } 
    315253 
     
    378316/** 
    379317 * tny_mozembed_msg_view_new: 
    380  * 
     318 * @save_strategy: The save strategy to use 
    381319 * 
    382320 * Return value: a new #TnyMsgViewIface instance implemented for Gtk+ 
    383321 **/ 
    384322TnyMozEmbedMsgView* 
    385 tny_moz_embed_msg_view_new (void
     323tny_moz_embed_msg_view_new (TnySaveStrategyIface *save_strategy
    386324{ 
    387325        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); 
    388328 
    389329        return self; 
     
    399339        GtkWidget *mitem = gtk_menu_item_new_with_mnemonic ("Save _As"); 
    400340        GtkTextBuffer *headerbuffer; 
     341 
     342        priv->save_strategy = NULL; 
    401343 
    402344        gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (self), NULL); 
     
    483425                g_object_unref (G_OBJECT (priv->msg)); 
    484426 
     427        if (G_LIKELY (priv->save_strategy)) 
     428                g_object_unref (G_OBJECT (priv->save_strategy)); 
     429 
    485430        (*parent_class->finalize) (object); 
    486431 
     
    494439 
    495440        klass->set_msg_func = tny_moz_embed_msg_view_set_msg; 
     441        klass->set_save_strategy_func = tny_mozembed_msg_view_set_save_strategy; 
    496442 
    497443        return; 
  • trunk/libtinymailui-mozembed/tny-moz-embed-msg-view.h

    r335 r347  
    2929#include <tny-stream-iface.h> 
    3030#include <tny-msg-mime-part-iface.h> 
     31#include <tny-save-strategy-iface.h> 
    3132 
    3233G_BEGIN_DECLS 
     
    5455 
    5556GType               tny_moz_embed_msg_view_get_type       (void); 
    56 TnyMozEmbedMsgView* tny_moz_embed_msg_view_new            (void); 
     57TnyMozEmbedMsgView* tny_moz_embed_msg_view_new            (TnySaveStrategyIface *save_strategy); 
    5758 
    5859G_END_DECLS 
  • trunk/libtinymailui/Makefile.am

    r340 r347  
    88        tny-summary-window-iface.h      \ 
    99        tny-msg-view-iface.h            \ 
     10        tny-save-strategy-iface.h       \ 
    1011        tny-msg-window-iface.h          \ 
    1112        tny-platform-factory-iface.h 
     
    1415        $(libtinymailui_1_0_headers)    \ 
    1516        tny-summary-window-iface.c      \ 
     17        tny-save-strategy-iface.c       \ 
    1618        tny-msg-view-iface.c            \ 
    1719        tny-msg-window-iface.c          \ 
  • trunk/libtinymailui/tny-msg-view-iface.c

    r212 r347  
    1919 
    2020#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 **/ 
     30void 
     31tny_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 
    2137 
    2238/** 
  • trunk/libtinymailui/tny-msg-view-iface.h

    r139 r347  
    2525#include <tny-shared.h> 
    2626 
     27#include <tny-save-strategy-iface.h> 
     28 
    2729G_BEGIN_DECLS 
    2830 
     
    4244        GTypeInterface parent; 
    4345 
    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); 
    4548}; 
    4649 
    47 GType         tny_msg_view_iface_get_type        (void); 
     50GType tny_msg_view_iface_get_type          (void); 
    4851 
    49 void          tny_msg_view_iface_set_msg         (TnyMsgViewIface *self, TnyMsgIface *msg); 
     52void  tny_msg_view_iface_set_msg           (TnyMsgViewIface *self, TnyMsgIface *msg); 
     53void  tny_msg_view_iface_set_save_strategy (TnyMsgViewIface *self, TnySaveStrategyIface *strategy); 
    5054 
    5155