[Libreoffice-commits] core.git: Branch 'feature/gsoc15-open-remote-files-dialog' - include/svtools svtools/source

Szymon Kłos eszkadev at gmail.com
Tue May 26 08:43:55 PDT 2015


 include/svtools/RemoteFilesDialog.hxx        |    6 +
 svtools/source/dialogs/RemoteFilesDialog.cxx |  112 ++++++++++++++-------------
 2 files changed, 65 insertions(+), 53 deletions(-)

New commits:
commit e313491d890ae0fdbf4e489eb5a6287daff186a3
Author: Szymon Kłos <eszkadev at gmail.com>
Date:   Tue May 26 17:42:04 2015 +0200

    added dispose method, which saves data only when were modified
    
    Change-Id: I791fe3aadc7ef21e105f62fcc1fb24e88d8dfe66

diff --git a/include/svtools/RemoteFilesDialog.hxx b/include/svtools/RemoteFilesDialog.hxx
index 32c00aa..4087188 100644
--- a/include/svtools/RemoteFilesDialog.hxx
+++ b/include/svtools/RemoteFilesDialog.hxx
@@ -38,10 +38,13 @@ class SVT_DLLPUBLIC RemoteFilesDialog : public ModalDialog
 public:
     RemoteFilesDialog(vcl::Window* pParent, WinBits nBits);
 
+    virtual void dispose() SAL_OVERRIDE;
+
 private:
     ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_context;
 
     SvtRemoteDlgMode m_eMode;
+    bool m_bIsUpdated;
 
     VclPtr<PushButton> m_pOpen_btn;
     VclPtr<PushButton> m_pSave_btn;
@@ -51,7 +54,8 @@ private:
 
     std::vector<ServicePtr> m_aServices;
 
-    void fillServicesListbox();
+    void FillServicesListbox();
+    unsigned int GetSelectedServicePos();
 
     DECL_LINK ( AddServiceHdl, void * );
     DECL_LINK_TYPED ( EditServiceMenuHdl, MenuButton *, void );
diff --git a/svtools/source/dialogs/RemoteFilesDialog.cxx b/svtools/source/dialogs/RemoteFilesDialog.cxx
index b69d4bd..d43578c 100644
--- a/svtools/source/dialogs/RemoteFilesDialog.cxx
+++ b/svtools/source/dialogs/RemoteFilesDialog.cxx
@@ -11,8 +11,6 @@
 
 using namespace ::com::sun::star::uno;
 
-const OUString sLocalFilePrefix = "file://";
-
 RemoteFilesDialog::RemoteFilesDialog(vcl::Window* pParent, WinBits nBits)
     : ModalDialog(pParent, "RemoteFilesDialog", "svt/ui/remotefilesdialog.ui")
     , m_context(comphelper::getProcessComponentContext())
@@ -24,6 +22,7 @@ RemoteFilesDialog::RemoteFilesDialog(vcl::Window* pParent, WinBits nBits)
     get(m_pServices_lb, "services_lb");
 
     m_eMode = (nBits & WB_SAVEAS) ? REMOTEDLG_MODE_SAVE : REMOTEDLG_MODE_OPEN;
+    m_bIsUpdated = false;
 
     if(m_eMode == REMOTEDLG_MODE_OPEN)
     {
@@ -40,10 +39,34 @@ RemoteFilesDialog::RemoteFilesDialog(vcl::Window* pParent, WinBits nBits)
     m_pAddService_btn->SetClickHdl( LINK( this, RemoteFilesDialog, AddServiceHdl ) );
     m_pAddService_btn->SetSelectHdl( LINK( this, RemoteFilesDialog, EditServiceMenuHdl ) );
 
-    fillServicesListbox();
+    FillServicesListbox();
 }
 
-void RemoteFilesDialog::fillServicesListbox()
+void RemoteFilesDialog::dispose()
+{
+    if(m_bIsUpdated)
+    {
+        Sequence< OUString > placesUrlsList(m_aServices.size());
+        Sequence< OUString > placesNamesList(m_aServices.size());
+
+        int i = 0;
+        for(std::vector<ServicePtr>::const_iterator it = m_aServices.begin(); it != m_aServices.end(); ++it)
+        {
+            placesUrlsList[i] = (*it)->GetUrl();
+            placesNamesList[i] = (*it)->GetName();
+            ++i;
+        }
+
+        std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
+        officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
+        officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
+        batch->commit();
+    }
+
+    ModalDialog::dispose();
+}
+
+void RemoteFilesDialog::FillServicesListbox()
 {
     m_pServices_lb->Clear();
     m_aServices.clear();
@@ -52,26 +75,41 @@ void RemoteFilesDialog::fillServicesListbox()
     Sequence< OUString > placesUrlsList(officecfg::Office::Common::Misc::FilePickerPlacesUrls::get(m_context));
     Sequence< OUString > placesNamesList(officecfg::Office::Common::Misc::FilePickerPlacesNames::get(m_context));
 
-    if(placesUrlsList.getLength() > 0 && placesNamesList.getLength() > 0)
+    for(sal_Int32 nPlace = 0; nPlace < placesUrlsList.getLength() && nPlace < placesNamesList.getLength(); ++nPlace)
     {
-        for(sal_Int32 nPlace = 0; nPlace < placesUrlsList.getLength() && nPlace < placesNamesList.getLength(); ++nPlace)
-        {
-            // Add only remote services, not local bookmarks
-            if(placesUrlsList[nPlace].compareTo(sLocalFilePrefix, sLocalFilePrefix.getLength()) != 0)
-            {
-                ServicePtr pService(new Place(placesNamesList[nPlace], placesUrlsList[nPlace], true));
-                m_aServices.push_back(pService);
+        ServicePtr pService(new Place(placesNamesList[nPlace], placesUrlsList[nPlace], true));
+        m_aServices.push_back(pService);
 
-                m_pServices_lb->InsertEntry(placesNamesList[nPlace]);
-            }
+        // Add to the listbox only remote services, not local bookmarks
+        if(!pService->IsLocal())
+        {
+            m_pServices_lb->InsertEntry(placesNamesList[nPlace]);
         }
+    }
 
+    if(m_pServices_lb->GetEntryCount() > 0)
         m_pServices_lb->SelectEntryPos(0);
-    }
     else
-    {
         m_pServices_lb->Enable(false);
+}
+
+unsigned int RemoteFilesDialog::GetSelectedServicePos()
+{
+    int nSelected = m_pServices_lb->GetSelectEntryPos();
+    unsigned int nPos = 0;
+    int i = -1;
+
+    while(nPos < m_aServices.size())
+    {
+        while(m_aServices[nPos]->IsLocal())
+            nPos++;
+        i++;
+        if(i == nSelected)
+            break;
+        nPos++;
     }
+
+    return nPos;
 }
 
 IMPL_LINK_NOARG ( RemoteFilesDialog, AddServiceHdl )
@@ -89,20 +127,7 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, AddServiceHdl )
             m_pServices_lb->InsertEntry(newService->GetName());
             m_pServices_lb->SelectEntryPos(m_pServices_lb->GetEntryCount() - 1);
 
-            // load all places (with local bookmarks), add new service and save all
-
-            Sequence< OUString > placesUrlsList(officecfg::Office::Common::Misc::FilePickerPlacesUrls::get(m_context));
-            placesUrlsList.realloc(placesUrlsList.getLength() + 1);
-            Sequence< OUString > placesNamesList(officecfg::Office::Common::Misc::FilePickerPlacesNames::get(m_context));
-            placesNamesList.realloc(placesNamesList.getLength() + 1);
-
-            placesUrlsList[placesUrlsList.getLength() - 1] = newService->GetUrl();
-            placesNamesList[placesNamesList.getLength() - 1] = newService->GetName();
-
-            std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
-            officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
-            officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
-            batch->commit();
+            m_bIsUpdated = true;
       break;
         }
         case RET_CANCEL :
@@ -120,40 +145,23 @@ IMPL_LINK_TYPED ( RemoteFilesDialog, EditServiceMenuHdl, MenuButton *, pButton,
     if(sIdent == "edit_service"  && m_pServices_lb->GetEntryCount() > 0)
     {
         unsigned int nSelected = m_pServices_lb->GetSelectEntryPos();
-        ScopedVclPtrInstance< PlaceEditDialog > aDlg(this, m_aServices[nSelected]);
+        unsigned int nPos = GetSelectedServicePos();
+
+        ScopedVclPtrInstance< PlaceEditDialog > aDlg(this, m_aServices[nPos]);
         short aRetCode = aDlg->Execute();
 
         switch(aRetCode)
         {
             case RET_OK :
             {
-                // load all places (with local bookmarks), edit service and save all
-
                 ServicePtr pEditedService = aDlg->GetPlace();
 
-                Sequence< OUString > placesUrlsList(officecfg::Office::Common::Misc::FilePickerPlacesUrls::get(m_context));
-                Sequence< OUString > placesNamesList(officecfg::Office::Common::Misc::FilePickerPlacesNames::get(m_context));
-
-                for(int i = 0; i < placesUrlsList.getLength() && i < placesNamesList[i].getLength(); i++)
-                {
-                    if(placesNamesList[i].compareTo(m_aServices[nSelected]->GetName()) == 0
-                       && placesUrlsList[i].compareTo(m_aServices[nSelected]->GetUrl()) == 0)
-                    {
-                        placesUrlsList[i] = pEditedService->GetUrl();
-                        placesNamesList[i] = pEditedService->GetName();
-                        break;
-                    }
-                }
-
-                m_aServices[nSelected] = pEditedService;
+                m_aServices[nPos] = pEditedService;
                 m_pServices_lb->RemoveEntry(nSelected);
                 m_pServices_lb->InsertEntry(pEditedService->GetName(), nSelected);
                 m_pServices_lb->SelectEntryPos(nSelected);
 
-                std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
-                officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
-                officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
-                batch->commit();
+                m_bIsUpdated = true;
         break;
             }
             case RET_CANCEL :


More information about the Libreoffice-commits mailing list