Update of /cvsroot/mahogany/M/src/modules
In directory usw-pr-cvs1:/tmp/cvs-serv28568/src/modules
Modified Files:
Migrate.cpp
Log Message:
fixes for creating file/directories
Index: Migrate.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/Migrate.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -b -u -2 -r1.8 -r1.9
--- Migrate.cpp 15 Oct 2002 11:00:11 -0000 1.8
+++ Migrate.cpp 15 Oct 2002 14:32:41 -0000 1.9
@@ -157,26 +157,9 @@
// add a new folder to folderNames/folderFlags arrays
- void AddFolder(const String& path, char delim, long flags)
- {
- source.delimiter = delim;
-
- // check if this folder is a child of the last one and remember it
- if ( countFolders )
- {
- String last = folderNames.Last();
- if ( last.empty() || path.StartsWith(last + delim) )
- {
- folderFlags.Last() &= ~ASMailFolder::ATT_NOINFERIORS;
- }
- }
+ void AddFolder(const String& path, char delim, long flags);
- // we abuse ATT_NOINFERIORS flag here to mean not only that the folder
- // doesn't have children but also to imply that a folder without this
- // flag does have children (which is not true for IMAP) -- initially it's
- // set as we don't have any children yet
- folderNames.Add(path);
- folderFlags.Add(flags | ASMailFolder::ATT_NOINFERIORS);
- countFolders++;
- }
+ // must be called at the end of folder enumeration to set the
+ // ATT_NOINFERIORS flags for the folders correctly
+ void FixFolderFlags();
};
@@ -483,4 +466,7 @@
void EnablePanelToBeUsed();
+ // enable/disable the "Forward" button
+ void UpdateForwardBtnUI(bool useIMAP);
+
private:
wxRadioButton *m_radioIMAP,
@@ -563,4 +549,7 @@
// process all folders
+ bool ProcessAllFolders();
+
+ // wrapper arounnd ProcessAllFolders()
void DoMigration();
@@ -1088,15 +1077,8 @@
}
-void MigrateWizardDstPage::OnRadioButton(wxCommandEvent& event)
+void MigrateWizardDstPage::UpdateForwardBtnUI(bool useIMAP)
{
- const bool useIMAP = event.GetEventObject() == m_radioIMAP;
- Data().toIMAP = useIMAP;
-
- EnablePanelToBeUsed();
-
if ( useIMAP )
{
- m_radioLocal->SetValue(false);
-
// button should be disabled if the server is not entered
m_panelIMAP->UpdateForwardBtnUI();
@@ -1104,6 +1086,4 @@
else // local dst
{
- m_radioIMAP->SetValue(false);
-
// button is always enabled
EnableButtons(MigrateWizard::Btn_Next, true);
@@ -1111,4 +1091,17 @@
}
+void MigrateWizardDstPage::OnRadioButton(wxCommandEvent& event)
+{
+ const bool useIMAP = event.GetEventObject() == m_radioIMAP;
+ Data().toIMAP = useIMAP;
+
+ EnablePanelToBeUsed();
+
+ UpdateForwardBtnUI(useIMAP);
+
+ // manually disable the other radiobox as we use wxRB_SINGLE
+ (useIMAP ? m_radioLocal : m_radioIMAP)->SetValue(false);
+}
+
bool MigrateWizardDstPage::TransferDataToWindow()
{
@@ -1121,6 +1114,13 @@
// call TransferDataToWindow() for both panels even if only one is used at
// any given moment
- return m_panelIMAP->TransferDataToWindow() &&
- m_panelLocal->TransferDataToWindow();
+ if ( !m_panelIMAP->TransferDataToWindow() ||
+ !m_panelLocal->TransferDataToWindow() )
+ {
+ return false;
+ }
+
+ UpdateForwardBtnUI(useIMAP);
+
+ return true;
}
@@ -1451,6 +1451,6 @@
if ( !(flags & ASMailFolder::ATT_NOINFERIORS) )
{
- // create a subdirectory for the subfolders
- if ( !wxMkdir(path) )
+ // create a subdirectory for the subfolders if it doesn't exist yet
+ if ( !wxPathExists(path) && !wxMkdir(path) )
{
wxLogWarning(_("Failed to create directory \"%s\" for folder \"%s\""),
@@ -1519,6 +1519,7 @@
else // local file destination
{
- // create a directory
- return wxMkdir(GetDstNameForSource(name));
+ // create a directory if it doesn't exist yet
+ const String dir = GetDstNameForSource(name);
+ return wxPathExists(dir) || wxMkdir(dir);
}
}
@@ -1535,4 +1536,14 @@
}
+ // don't create the target folder if the destination is empty and has
+ // subfolders: i.e. we do create empty folders if they contain messages only
+ // but we want to avoid creating empty "folder.messages" files if we have a
+ // "folder" directory
+ if ( !(flags & ASMailFolder::ATT_NOINFERIORS) && !mf->GetMessageCount() )
+ {
+ // nothing to do
+ return true;
+ }
+
// create the folder to save the messages to
MFolder_obj folderDst = GetDstFolder(name, flags);
@@ -1540,5 +1551,5 @@
if ( !mfDst )
{
- wxLogError(_("Failed to create the targer folder \"%s\""), name.c_str());
+ wxLogError(_("Failed to create the target folder \"%s\""), name.c_str());
return false;
@@ -1549,7 +1560,22 @@
}
-void MigrateWizardProgressPage::DoMigration()
+bool MigrateWizardProgressPage::ProcessAllFolders()
{
- EnableWizardButtons(false);
+ // ensure that the directory where we're going to create our files exists
+ if ( !Data().toIMAP )
+ {
+ const String& dir = Data().dstLocal.root;
+ if ( !dir.empty() && !wxPathExists(dir) )
+ {
+ if ( !wxMkdir(dir) )
+ {
+ wxLogError(_("Can't create the directory for the mailbox files.\n"
+ "\n"
+ "Migration aborted"));
+
+ return false;
+ }
+ }
+ }
for ( m_nFolder = 0, m_nErrors = 0;
@@ -1562,5 +1588,5 @@
break;
}
-;
+
const String& name = Data().folderNames[m_nFolder];
@@ -1588,9 +1614,28 @@
}
+ return true;
+}
+
+void MigrateWizardProgressPage::DoMigration()
+{
+ EnableWizardButtons(false);
+
+ bool ok = ProcessAllFolders();
+
// update the UI to show that we're done now
- if ( m_continue )
- {
m_btnAbort->Disable();
+ m_labelFolder->Disable();
+ m_gaugeFolder->Disable();
+ m_labelMsg->Disable();
+ m_gaugeMsg->Disable();
+
+ String msg;
+ if ( !ok )
+ {
+ msg = _("Migration couldn't be done.");
+ }
+ else if ( m_continue )
+ {
m_gaugeMsg->SetValue(m_countMessages);
m_gaugeFolder->SetValue(Data().countFolders);
@@ -1607,10 +1652,14 @@
msg = _("Completed successfully.");
}
+ }
+ else // cancelled
+ {
+ msg = _("Migration aborted.");
+ }
UpdateStatus(msg);
+ // let the user dismiss the wizard now
EnableWizardButtons(true);
- }
- //else: cancelled
wxWindow *btnFinish = GetParent()->FindWindow(wxID_FORWARD);
@@ -1645,14 +1694,4 @@
{
m_continue = false;
-
- m_btnAbort->Disable();
- m_labelFolder->Disable();
- m_gaugeFolder->Disable();
- m_labelMsg->Disable();
- m_gaugeMsg->Disable();
-
- UpdateStatus(_("Migration aborted."));
-
- EnableWizardButtons(true);
}
}
@@ -1876,5 +1915,43 @@
MigrateWizard::OnNoMoreFolders()
{
+ Data().FixFolderFlags();
+
m_doneWithList = true;
+}
+
+// ----------------------------------------------------------------------------
+// MigrateData implementation
+// ----------------------------------------------------------------------------
+
+void MigrateData::AddFolder(const String& path, char delim, long flags)
+{
+ source.delimiter = delim;
+
+ // we abuse ATT_NOINFERIORS flag here to mean not only that the folder
+ // doesn't have children but also to imply that a folder without this
+ // flag does have children (which is not true for IMAP) -- initially it's
+ // set as we don't have any children yet and we correct it in
+ // FixFolderFlags() later
+ folderNames.Add(path);
+ folderFlags.Add(flags | ASMailFolder::ATT_NOINFERIORS);
+ countFolders++;
+}
+
+void MigrateData::FixFolderFlags()
+{
+ for ( int n = 0; n < countFolders; n++ )
+ {
+ // check if this folder is a child of some of the previous folders
+ String parent = folderNames[n].BeforeLast(source.delimiter);
+ if ( !parent.empty() )
+ {
+ int idx = folderNames.Index(parent);
+ if ( idx != wxNOT_FOUND )
+ {
+ // this one does have children
+ folderFlags[(size_t)idx] &= ~ASMailFolder::ATT_NOINFERIORS;
+ }
+ }
+ }
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates