Revision: 7483
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7483&view=rev
Author:   vadz
Date:     2008-05-22 19:15:37 -0700 (Thu, 22 May 2008)

Log Message:
-----------
allow saving the filters to any config source, not just the local one

Modified Paths:
--------------
    trunk/M/M.vcproj
    trunk/M/include/gui/wxDialogLayout.h
    trunk/M/src/gui/wxDialogLayout.cpp
    trunk/M/src/gui/wxFiltersDialog.cpp

Added Paths:
-----------
    trunk/M/include/gui/ConfigSourceChoice.h
    trunk/M/src/gui/ConfigSourceChoice.cpp

Modified: trunk/M/M.vcproj
===================================================================
--- trunk/M/M.vcproj    2008-05-23 00:54:53 UTC (rev 7482)
+++ trunk/M/M.vcproj    2008-05-23 02:15:37 UTC (rev 7483)
@@ -377,6 +377,9 @@
                                        RelativePath=".\src\gui\ClickURL.cpp">
                                </File>
                                <File
+                                       
RelativePath=".\src\gui\ConfigSourceChoice.cpp">
+                               </File>
+                               <File
                                        RelativePath=".\src\gui\Mdnd.cpp">
                                </File>
                                <File

Added: trunk/M/include/gui/ConfigSourceChoice.h
===================================================================
--- trunk/M/include/gui/ConfigSourceChoice.h                            (rev 0)
+++ trunk/M/include/gui/ConfigSourceChoice.h    2008-05-23 02:15:37 UTC (rev 
7483)
@@ -0,0 +1,54 @@
+///////////////////////////////////////////////////////////////////////////////
+// Project:     M - cross platform e-mail GUI client
+// File name:   gui/ConfigSourceChoice.h
+// Purpose:     Declaration of ConfigSourceChoice class
+// Author:      Vadim Zeitlin
+// Created:     2008-05-23
+// CVS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <[EMAIL PROTECTED]>
+// Licence:     M license
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef M_GUI_CONFIGSOURCE_H
+#define M_GUI_CONFIGSOURCE_H
+
+#include "ConfigSource.h"
+
+#include <wx/choice.h>
+
+/**
+   A choice control allowing the user to select the config source to use.
+
+   It provides a convenient creation method and direct access to the selected
+   config source.
+ */
+class ConfigSourceChoice : public wxChoice
+{
+public:
+   /**
+      Create a choice control containing all the config sources.
+
+      This is useful for option editing dialogs which need to allow the user to
+      choose the config source where the changes should be saved.
+      
+      If there are no config sources defined, returns NULL. Otherwise returns
+      the choice control with their names and positions it in the bottom right
+      corner of the @a parent offset by the margin plus @a hExtra from the
+      bottom. As the bottom row is normally taken by the buttons, the usual
+      value for hExtra will be wxManuallyLaidOutDialog::hBtn.
+    */
+   static ConfigSourceChoice *Create(wxWindow *parent, int hExtra);
+
+   /**
+      Return the selected config source.
+
+      May return NULL if there is no selection.
+    */
+   ConfigSource *GetSelectedSource() const;
+
+private:
+   // ctor is private, we're only created by Create()
+   ConfigSourceChoice(wxWindow *parent) : wxChoice(parent, wxID_ANY) { }
+};
+
+#endif // M_GUI_CONFIGSOURCE_H


Property changes on: trunk/M/include/gui/ConfigSourceChoice.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/M/include/gui/wxDialogLayout.h
===================================================================
--- trunk/M/include/gui/wxDialogLayout.h        2008-05-23 00:54:53 UTC (rev 
7482)
+++ trunk/M/include/gui/wxDialogLayout.h        2008-05-23 02:15:37 UTC (rev 
7483)
@@ -262,7 +262,7 @@
 
 
    // choice containing all config sources, may be NULL
-   wxChoice *m_chcSources;
+   class ConfigSourceChoice *m_chcSources;
 
    // original config source used by profile returned by GetProfile(): only
    // valid if m_changedConfigSource == true

Added: trunk/M/src/gui/ConfigSourceChoice.cpp
===================================================================
--- trunk/M/src/gui/ConfigSourceChoice.cpp                              (rev 0)
+++ trunk/M/src/gui/ConfigSourceChoice.cpp      2008-05-23 02:15:37 UTC (rev 
7483)
@@ -0,0 +1,97 @@
+///////////////////////////////////////////////////////////////////////////////
+// Project:     M - cross platform e-mail GUI client
+// File name:   gui/ConfigSourceChoice.cpp
+// Purpose:     Implementation of ConfigSourceChoice class
+// Author:      Vadim Zeitlin
+// Created:     2008-05-23
+// CVS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <[EMAIL PROTECTED]>
+// Licence:     M license
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "Mpch.h"
+
+#ifndef USE_PCH
+#  include "Mcommon.h"
+#endif
+
+#include "ConfigSourcesAll.h"
+
+#include "gui/ConfigSourceChoice.h"
+
+#include <wx/statline.h>
+
+// ============================================================================
+// ConfigSourceChoice implementation
+// ============================================================================
+
+/* static */
+ConfigSourceChoice *
+ConfigSourceChoice::Create(wxWindow *parent, int hExtra)
+{
+   const AllConfigSources::List& sources = 
AllConfigSources::Get().GetSources();
+   if ( sources.size() == 1 )
+      return NULL;
+
+   ConfigSourceChoice * const chcSources = new ConfigSourceChoice(parent);
+
+   for ( AllConfigSources::List::iterator i = sources.begin(),
+                                        end = sources.end();
+         i != end;
+         ++i )
+   {
+      chcSources->Append(i->GetName());
+   }
+
+   wxLayoutConstraints *c;
+
+   c = new wxLayoutConstraints;
+   c->right.SameAs(parent, wxRight, LAYOUT_X_MARGIN);
+   c->width.AsIs();
+   c->height.AsIs();
+   c->bottom.SameAs(parent, wxBottom, 5*LAYOUT_Y_MARGIN + hExtra);
+   chcSources->SetConstraints(c);
+
+   wxStaticText *label = new wxStaticText(parent, -1, _("&Save changes to:"));
+   c = new wxLayoutConstraints;
+   c->right.LeftOf(chcSources, LAYOUT_X_MARGIN);
+   c->width.AsIs();
+   c->height.AsIs();
+   c->centreY.SameAs(chcSources, wxCentreY);
+   label->SetConstraints(c);
+
+   wxStaticLine *line = new wxStaticLine(parent, -1);
+   c = new wxLayoutConstraints;
+   c->left.SameAs(parent, wxLeft, LAYOUT_X_MARGIN);
+   c->right.SameAs(parent, wxRight, LAYOUT_X_MARGIN);
+   c->height.AsIs();
+   c->bottom.Above(chcSources, -LAYOUT_Y_MARGIN);
+   line->SetConstraints(c);
+
+   return chcSources;
+}
+
+ConfigSource *ConfigSourceChoice::GetSelectedSource() const
+{
+   const int sel = GetSelection();
+   ConfigSource *config = NULL;
+   if ( sel != wxNOT_FOUND )
+   {
+      AllConfigSources::List::iterator
+         i = AllConfigSources::Get().GetSources().begin();
+      for ( int n = 0; n < sel; n++ )
+         ++i;
+
+      config = i.operator->();
+   }
+
+   return config;
+}


Property changes on: trunk/M/src/gui/ConfigSourceChoice.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/M/src/gui/wxDialogLayout.cpp
===================================================================
--- trunk/M/src/gui/wxDialogLayout.cpp  2008-05-23 00:54:53 UTC (rev 7482)
+++ trunk/M/src/gui/wxDialogLayout.cpp  2008-05-23 02:15:37 UTC (rev 7483)
@@ -48,12 +48,11 @@
 #include <wx/imaglist.h>
 #include <wx/statline.h>
 
+#include "gui/ConfigSourceChoice.h"
 #include "gui/wxOptionsPage.h"
 #include "gui/wxBrowseButton.h"
 #include "gui/wxMenuDefs.h"
 
-#include "ConfigSourcesAll.h"
-
 #include "Mupgrade.h"      // for VerifyEMailSendingWorks()
 
 // ----------------------------------------------------------------------------
@@ -1292,20 +1291,9 @@
 void
 wxProfileSettingsEditDialog::ApplyConfigSourceSelectedByUser(Profile& profile)
 {
-   const int sel = m_chcSources->GetSelection();
-   ConfigSource *config = NULL;
-   if ( sel != -1 )
-   {
-      AllConfigSources::List::iterator
-         i = AllConfigSources::Get().GetSources().begin();
-      for ( int n = 0; n < sel; n++ )
-         ++i;
+   ConfigSource * const configOld =
+      profile.SetConfigSourceForWriting(m_chcSources->GetSelectedSource());
 
-      config = i.operator->();
-   }
-
-   ConfigSource *configOld = profile.SetConfigSourceForWriting(config);
-
    // remember the original config source if this is the first time we change
    // it
    if ( !m_changedConfigSource )
@@ -1335,56 +1323,17 @@
    wxManuallyLaidOutDialog::EndModal(rc);
 }
 
-
 wxControl *wxProfileSettingsEditDialog::CreateControlsBelow(wxPanel *panel)
 {
-   const AllConfigSources::List& sources = 
AllConfigSources::Get().GetSources();
-   if ( sources.size() == 1 )
+   m_chcSources = ConfigSourceChoice::Create(panel, hBtn);
+   if ( m_chcSources )
    {
-      m_chcSources = NULL;
-      return NULL;
+      Connect(wxEVT_COMMAND_CHOICE_SELECTED,
+                wxCommandEventHandler(
+                   wxProfileSettingsEditDialog::OnConfigSourceChange));
    }
 
-   m_chcSources = new wxChoice(panel, -1);
-
-   Connect(wxEVT_COMMAND_CHOICE_SELECTED,
-             wxCommandEventHandler(
-                wxProfileSettingsEditDialog::OnConfigSourceChange));
-
-   for ( AllConfigSources::List::iterator i = sources.begin(),
-                                        end = sources.end();
-         i != end;
-         ++i )
-   {
-      m_chcSources->Append(i->GetName());
-   }
-
-   wxLayoutConstraints *c;
-
-   c = new wxLayoutConstraints;
-   c->right.SameAs(panel, wxRight, LAYOUT_X_MARGIN);
-   c->width.AsIs();
-   c->height.AsIs();
-   c->bottom.SameAs(panel, wxBottom, 5*LAYOUT_Y_MARGIN + hBtn);
-   m_chcSources->SetConstraints(c);
-
-   wxStaticText *label = new wxStaticText(panel, -1, _("&Save changes to:"));
-   c = new wxLayoutConstraints;
-   c->right.LeftOf(m_chcSources, LAYOUT_X_MARGIN);
-   c->width.AsIs();
-   c->height.AsIs();
-   c->centreY.SameAs(m_chcSources, wxCentreY);
-   label->SetConstraints(c);
-
-   wxStaticLine *line = new wxStaticLine(panel, -1);
-   c = new wxLayoutConstraints;
-   c->left.SameAs(panel, wxLeft, LAYOUT_X_MARGIN);
-   c->right.SameAs(panel, wxRight, LAYOUT_X_MARGIN);
-   c->height.AsIs();
-   c->bottom.Above(m_chcSources, -LAYOUT_Y_MARGIN);
-   line->SetConstraints(c);
-
-   return line;
+   return m_chcSources;
 }
 
 void wxProfileSettingsEditDialog::CreateAllControls()

Modified: trunk/M/src/gui/wxFiltersDialog.cpp
===================================================================
--- trunk/M/src/gui/wxFiltersDialog.cpp 2008-05-23 00:54:53 UTC (rev 7482)
+++ trunk/M/src/gui/wxFiltersDialog.cpp 2008-05-23 02:15:37 UTC (rev 7483)
@@ -42,6 +42,7 @@
 #include "MModule.h"
 #include "SpamFilter.h"
 
+#include "gui/ConfigSourceChoice.h"
 #include "gui/wxBrowseButton.h"
 #include "gui/wxDialogLayout.h"
 #include "gui/wxFiltersDialog.h"
@@ -319,10 +320,11 @@
 
 // create a new filter, return its name (or an empty string if the filter
 // creation was cancelled)
-static String CreateNewFilter(wxWindow *parent);
+static String CreateNewFilter(wxWindow *parent, ConfigSource *config = NULL);
 
 // edit the filter with given name, return TRUE if anything changed
-static bool EditFilter(const String& name, wxWindow *parent);
+static bool
+EditFilter(const String& name, wxWindow *parent, ConfigSource *config = NULL);
 
 // ----------------------------------------------------------------------------
 // private classes
@@ -335,14 +337,11 @@
 // wxOneFilterDialog - dialog for exactly one filter rule
 // ----------------------------------------------------------------------------
 
-/**
-   A class representing the configuration GUI for a single filter.
- */
 class wxOneFilterDialog : public wxManuallyLaidOutDialog
 {
 public:
    // ctor & dtor
-   wxOneFilterDialog(class MFilterDesc *fd, wxWindow *parent);
+   wxOneFilterDialog(MFilterDesc *fd, wxWindow *parent);
    virtual ~wxOneFilterDialog();
 
    // transfer data to/from dialog
@@ -1577,6 +1576,10 @@
    // listbox contains the names of all filters
    wxListBox *m_lboxFilters;
 
+   // contains the config source to use for saving the changes in this dialog,
+   // may be NULL if no specific config source needs to be used
+   ConfigSourceChoice *m_chcSources;
+
    // did anything change?
    bool m_hasChanges;
 
@@ -1613,7 +1616,7 @@
 
    wxLayoutConstraints *c;
 
-   wxStaticBox *box = CreateStdButtonsAndBox(wxEmptyString, FALSE,
+   wxStaticBox *box = CreateStdButtonsAndBox(_("All &filters:"), FALSE,
                                              MH_DIALOG_FILTERS);
 
    /* This dialog is supposed to look like this:
@@ -1687,8 +1690,21 @@
                                   wxLB_SORT);
    m_lboxFilters->SetConstraints(c);
 
-   SetDefaultSize(5*wBtn, 11*hBtn);
+   // deal with optional "Save changes to" combobox
+   int heightDef = 11*hBtn;
 
+   m_chcSources = ConfigSourceChoice::Create(this, hBtn);
+   if ( m_chcSources )
+   {
+      heightDef += hBtn;
+
+      // we need to adjust the box constraints as it shouldn't extend down to
+      // the buttons
+      box->GetConstraints()->bottom.SameAs(m_chcSources, wxTop, 
LAYOUT_Y_MARGIN);
+   }
+
+   SetDefaultSize(5*wBtn, heightDef);
+
    m_lboxFilters->SetFocus();
 }
 
@@ -1699,8 +1715,13 @@
 void
 wxAllFiltersDialog::OnAddFiter(wxCommandEvent& /* event */)
 {
-   String name = CreateNewFilter(this);
-   if ( !name )
+   // ensure that we save changes to the selected config source, if any
+   ConfigSource * const config = m_chcSources
+                                    ? m_chcSources->GetSelectedSource()
+                                    : NULL;
+
+   const String name = CreateNewFilter(this, config);
+   if ( name.empty() )
    {
       // cancelled
       return;
@@ -1712,7 +1733,7 @@
       m_lboxFilters->Append(name);
 
       // a newly added filter is not used by any folders yet, but this could
-      // be surprizing (well, in fact, it's really bad design and we should
+      // be surprising (well, in fact, it's really bad design and we should
       // just allow to configure the folders which use this filter in the
       // wxOneFilterDialog - TODO)
       String msg;
@@ -1733,6 +1754,9 @@
          MFolder_obj folder(MDialog_FolderChoose(this));
          if ( folder )
          {
+            Profile_obj profile(folder->GetProfile());
+            ProfileConfigSourceChange change(profile, config);
+
             // activate the filter for this folder
             folder->AddFilter(name);
          }
@@ -1780,7 +1804,8 @@
    String name = m_lboxFilters->GetStringSelection();
    CHECK_RET( !!name, _T("must have selection in the listbox") );
 
-   if ( EditFilter(name, this) )
+   if ( EditFilter(name, this, m_chcSources ? m_chcSources->GetSelectedSource()
+                                            : NULL) )
    {
       // filter changed
       m_hasChanges = true;
@@ -2595,7 +2620,7 @@
    return false;
 }
 
-static String CreateNewFilter(wxWindow *parent)
+static String CreateNewFilter(wxWindow *parent, ConfigSource *config)
 {
    String name;
    MFilterDesc fd;
@@ -2619,14 +2644,27 @@
 
       // create the new filter
       MFilter_obj filter(name);
+
+      // ensure that it is saved to the specified config source
+      Profile_obj profileFilter(filter->GetProfile());
+      ProfileConfigSourceChange change(profileFilter, config);
+
       filter->Set(fd);
+
+      // if we don't do this, ProfileConfigSourceChange dtor would be executed
+      // before MFilter one which is where the filter is really saved to config
+      {
+         MFilter_obj filterNull;
+         filter.Swap(filterNull);
+      }
    }
    //else: cancelled
 
    return name;
 }
 
-static bool EditFilter(const String& name, wxWindow *parent)
+static bool
+EditFilter(const String& name, wxWindow *parent, ConfigSource *config)
 {
    MFilter_obj filter(name);
    CHECK( filter, false, _T("filter unexpectedly missing") );
@@ -2638,6 +2676,10 @@
       return false;
    }
 
+   // ensure it's saved to the specified config source
+   Profile_obj profileFilter(filter->GetProfile());
+   ProfileConfigSourceChange change(profileFilter, config);
+
    filter->Set(fd);
 
    return true;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to