[haiku-commits] haiku: hrev47503 - src/kits/tracker

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 16 Jul 2014 14:46:19 +0200 (CEST)

hrev47503 adds 1 changeset to branch 'master'
old head: 62f70e6f0ad0f5896250903736e47183facf6077
new head: dd03c93fbffc21c83f9188e6560c6a023c056fd6
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=dd03c93+%5E62f70e6

----------------------------------------------------------------------------

dd03c93: Move automount settings to the Tracker preferences
  
  * Avoids the ugly "button that opens another window" UI paradigm in
  Tracker preferences.
  * Makes it possible to revert changes to the automount settings as the
  Tracker preferences window has a revert button.

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev47503
Commit:      dd03c93fbffc21c83f9188e6560c6a023c056fd6
URL:         http://cgit.haiku-os.org/haiku/commit/?id=dd03c93
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Wed Jul 16 12:42:30 2014 UTC

----------------------------------------------------------------------------

7 files changed, 153 insertions(+), 189 deletions(-)
src/kits/tracker/AutoMounterSettings.cpp   | 190 +++++++++++--------------
src/kits/tracker/AutoMounterSettings.h     |  59 --------
src/kits/tracker/SettingsViews.cpp         |  10 --
src/kits/tracker/SettingsViews.h           |  42 +++++-
src/kits/tracker/Tracker.cpp               |  15 +-
src/kits/tracker/TrackerSettingsWindow.cpp |  17 ++-
src/kits/tracker/TrackerSettingsWindow.h   |   9 ++

----------------------------------------------------------------------------

diff --git a/src/kits/tracker/AutoMounterSettings.cpp 
b/src/kits/tracker/AutoMounterSettings.cpp
index f34a926..9f29fa5 100644
--- a/src/kits/tracker/AutoMounterSettings.cpp
+++ b/src/kits/tracker/AutoMounterSettings.cpp
@@ -33,8 +33,6 @@ All rights reserved.
 */
 
 
-#include "AutoMounterSettings.h"
-
 #include <Alert.h>
 #include <Box.h>
 #include <Button.h>
@@ -52,6 +50,8 @@ All rights reserved.
 
 #include <MountServer.h>
 
+#include "SettingsViews.h"
+
 
 #undef B_TRANSLATION_CONTEXT
 #define B_TRANSLATION_CONTEXT "AutoMounterSettings"
@@ -62,50 +62,13 @@ const uint32 kBootMountSettingsChanged = 'bchg';
 const uint32 kEjectWhenUnmountingChanged = 'ejct';
 
 
-class AutomountSettingsPanel : public BBox {
-public:
-                                                               
AutomountSettingsPanel(BMessage* settings,
-                                                                       const 
BMessenger& target);
-       virtual                                         
~AutomountSettingsPanel();
-
-protected:
-       virtual void                            MessageReceived(BMessage* 
message);
-       virtual void                            AttachedToWindow();
-
-private:
-                       void                            _SendSettings(bool 
rescan);
-
-                       BRadioButton*           fInitialDontMountCheck;
-                       BRadioButton*           fInitialMountAllBFSCheck;
-                       BRadioButton*           fInitialMountAllCheck;
-                       BRadioButton*           fInitialMountRestoreCheck;
-
-                       BRadioButton*           fScanningDisabledCheck;
-                       BRadioButton*           fAutoMountAllBFSCheck;
-                       BRadioButton*           fAutoMountAllCheck;
-
-                       BCheckBox*                      
fEjectWhenUnmountingCheckBox;
-
-                       BButton*                        fDone;
-                       BButton*                        fMountAllNow;
-
-                       BMessenger                      fTarget;
-
-                       typedef BBox _inherited;
-};
-
-
-AutomountSettingsDialog* AutomountSettingsDialog::sOneCopyOnly = NULL;
-
-
 //     #pragma mark - AutomountSettingsPanel
 
 
-AutomountSettingsPanel::AutomountSettingsPanel(BMessage* settings,
-       const BMessenger& target)
+AutomountSettingsPanel::AutomountSettingsPanel()
        :
-       BBox("", B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER),
-       fTarget(target)
+       SettingsView(""),
+       fTarget(kMountServerSignature)
 {
        const float spacing = be_control_look->DefaultItemSpacing();
 
@@ -161,13 +124,9 @@ AutomountSettingsPanel::AutomountSettingsPanel(BMessage* 
settings,
 
        // Buttons
 
-       fDone = new BButton(B_TRANSLATE("Done"), new 
BMessage(B_QUIT_REQUESTED));
-
        fMountAllNow = new BButton("mountAll", B_TRANSLATE("Mount all disks 
now"),
                new BMessage(kMountAllNow));
 
-       fDone->MakeDefault(true);
-
        // Layout the controls
 
        BGroupView* contentView = new BGroupView(B_VERTICAL, 0);
@@ -190,42 +149,58 @@ AutomountSettingsPanel::AutomountSettingsPanel(BMessage* 
settings,
                        .End()
                .Add(new BSeparatorView(B_HORIZONTAL/*, B_FANCY_BORDER*/))
                .AddGroup(B_HORIZONTAL, spacing)
-                       .SetInsets(0, spacing, spacing, spacing)
-                       .AddGlue()
+                       .SetInsets(spacing, spacing, spacing, spacing)
                        .Add(fMountAllNow)
-                       .Add(fDone);
+                       .AddGlue();
 
-       // Apply the settings
+       ShowCurrentSettings();
+}
 
-       bool result;
-       if (settings->FindBool("autoMountAll", &result) == B_OK && result)
-               fAutoMountAllCheck->SetValue(B_CONTROL_ON);
-       else if (settings->FindBool("autoMountAllBFS", &result) == B_OK && 
result)
-               fAutoMountAllBFSCheck->SetValue(B_CONTROL_ON);
-       else
-               fScanningDisabledCheck->SetValue(B_CONTROL_ON);
 
-       if (settings->FindBool("suspended", &result) == B_OK && result)
-               fScanningDisabledCheck->SetValue(B_CONTROL_ON);
+AutomountSettingsPanel::~AutomountSettingsPanel()
+{
+}
 
-       if (settings->FindBool("initialMountAll", &result) == B_OK && result)
-               fInitialMountAllCheck->SetValue(B_CONTROL_ON);
-       else if (settings->FindBool("initialMountRestore", &result) == B_OK
-               && result) {
-               fInitialMountRestoreCheck->SetValue(B_CONTROL_ON);
-       } else if (settings->FindBool("initialMountAllBFS", &result) == B_OK
-               && result) {
-               fInitialMountAllBFSCheck->SetValue(B_CONTROL_ON);
-       } else
-               fInitialDontMountCheck->SetValue(B_CONTROL_ON);
 
-       if (settings->FindBool("ejectWhenUnmounting", &result) == B_OK && 
result)
-               fEjectWhenUnmountingCheckBox->SetValue(B_CONTROL_ON);
+bool
+AutomountSettingsPanel::IsDefaultable() const
+{
+       return false;
 }
 
 
-AutomountSettingsPanel::~AutomountSettingsPanel()
+void
+AutomountSettingsPanel::Revert()
+{
+       _ParseSettings(fInitialSettings);
+       _SendSettings(false);
+}
+
+
+void
+AutomountSettingsPanel::ShowCurrentSettings()
+{
+       // Apply the settings
+       BMessage settings;
+       _GetSettings(&settings);
+       _ParseSettings(settings);
+}
+
+
+void
+AutomountSettingsPanel::RecordRevertSettings()
+{
+       _GetSettings(&fInitialSettings);
+}
+
+
+bool
+AutomountSettingsPanel::IsRevertable() const
 {
+       BMessage currentSettings;
+       _GetSettings(&currentSettings);
+
+       return !currentSettings.HasSameData(fInitialSettings);
 }
 
 
@@ -242,7 +217,6 @@ AutomountSettingsPanel::AttachedToWindow()
        fScanningDisabledCheck->SetTarget(this);
        fEjectWhenUnmountingCheckBox->SetTarget(this);
 
-       fDone->SetTarget(this);
        fMountAllNow->SetTarget(fTarget);
 }
 
@@ -296,55 +270,53 @@ AutomountSettingsPanel::_SendSettings(bool rescan)
                (bool)fEjectWhenUnmountingCheckBox->Value());
 
        fTarget.SendMessage(&message);
-}
-
 
-//     #pragma mark - AutomountSettingsDialog
-
-
-AutomountSettingsDialog::AutomountSettingsDialog(BMessage* settings,
-       const BMessenger& target)
-       :
-       BWindow(BRect(100, 100, 320, 370), B_TRANSLATE("Disk mount settings"),
-               B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
-                       | B_AUTO_UPDATE_SIZE_LIMITS)
-{
-       SetLayout(new BGroupLayout(B_HORIZONTAL));
-       BView* view = new AutomountSettingsPanel(settings, target);
-       AddChild(view);
-
-       ASSERT(!sOneCopyOnly);
-       sOneCopyOnly = this;
-}
-
-
-AutomountSettingsDialog::~AutomountSettingsDialog()
-{
-       ASSERT(sOneCopyOnly);
-       sOneCopyOnly = NULL;
+       // Tell the settings window the contents have changed:
+       Window()->PostMessage(kSettingsContentsModified);
 }
 
 
 void
-AutomountSettingsDialog::RunAutomountSettings(const BMessenger& target)
+AutomountSettingsPanel::_GetSettings(BMessage* reply) const
 {
-       // either activate an existing mount settings dialog or create a new one
-       if (sOneCopyOnly != NULL) {
-               sOneCopyOnly->Activate();
-               return;
-       }
-
        BMessage message(kGetAutomounterParams);
-       BMessage reply;
-       if (target.SendMessage(&message, &reply, 2500000) != B_OK) {
+       if (fTarget.SendMessage(&message, reply, 2500000) != B_OK) {
                BAlert* alert = new BAlert(B_TRANSLATE("Mount server error"),
                        B_TRANSLATE("The mount server could not be contacted."),
                        B_TRANSLATE("OK"),
                        NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
                alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
                alert->Go();
-               return;
        }
+}
+
+
+void
+AutomountSettingsPanel::_ParseSettings(const BMessage& settings)
+{
+       bool result;
+       if (settings.FindBool("autoMountAll", &result) == B_OK && result)
+               fAutoMountAllCheck->SetValue(B_CONTROL_ON);
+       else if (settings.FindBool("autoMountAllBFS", &result) == B_OK && 
result)
+               fAutoMountAllBFSCheck->SetValue(B_CONTROL_ON);
+       else
+               fScanningDisabledCheck->SetValue(B_CONTROL_ON);
+
+       if (settings.FindBool("suspended", &result) == B_OK && result)
+               fScanningDisabledCheck->SetValue(B_CONTROL_ON);
 
-       (new AutomountSettingsDialog(&reply, target))->Show();
+       if (settings.FindBool("initialMountAll", &result) == B_OK && result)
+               fInitialMountAllCheck->SetValue(B_CONTROL_ON);
+       else if (settings.FindBool("initialMountRestore", &result) == B_OK
+               && result) {
+               fInitialMountRestoreCheck->SetValue(B_CONTROL_ON);
+       } else if (settings.FindBool("initialMountAllBFS", &result) == B_OK
+               && result) {
+               fInitialMountAllBFSCheck->SetValue(B_CONTROL_ON);
+       } else
+               fInitialDontMountCheck->SetValue(B_CONTROL_ON);
+
+       if (settings.FindBool("ejectWhenUnmounting", &result) == B_OK && result)
+               fEjectWhenUnmountingCheckBox->SetValue(B_CONTROL_ON);
 }
+
diff --git a/src/kits/tracker/AutoMounterSettings.h 
b/src/kits/tracker/AutoMounterSettings.h
deleted file mode 100644
index 40d0332..0000000
--- a/src/kits/tracker/AutoMounterSettings.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
-Open Tracker License
-
-Terms and Conditions
-
-Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice applies to all licensees
-and shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN 
CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of Be Incorporated shall not be
-used in advertising or otherwise to promote the sale, use or other dealings in
-this Software without prior written authorization from Be Incorporated.
-
-Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered 
trademarks
-of Be Incorporated in the United States and other countries. Other brand 
product
-names are registered trademarks or trademarks of their respective holders.
-All rights reserved.
-*/
-#ifndef _AUTOMOUNTER_SETTINGS_H
-#define _AUTOMOUNTER_SETTINGS_H
-
-
-#include <Window.h>
-
-
-namespace BPrivate {
-
-class AutomountSettingsDialog : public BWindow {
-       public:
-               AutomountSettingsDialog(BMessage* settings, const BMessenger 
&target);
-               virtual ~AutomountSettingsDialog();
-
-               static void RunAutomountSettings(const BMessenger &target);
-
-       private:
-               static AutomountSettingsDialog* sOneCopyOnly;
-};
-
-} // namespace BPrivate
-
-using namespace BPrivate;
-
-
-#endif // _AUTOMOUNTER_SETTINGS_H
diff --git a/src/kits/tracker/SettingsViews.cpp 
b/src/kits/tracker/SettingsViews.cpp
index a8f26eb..453fefd 100644
--- a/src/kits/tracker/SettingsViews.cpp
+++ b/src/kits/tracker/SettingsViews.cpp
@@ -189,10 +189,6 @@ DesktopSettingsView::DesktopSettingsView()
                B_TRANSLATE("Show shared volumes on Desktop"),
                new BMessage(kVolumesOnDesktopChanged));
 
-       fMountButton = new BButton("",
-               B_TRANSLATE("Mount settings" B_UTF8_ELLIPSIS),
-               new BMessage(kRunAutomounterSettings));
-
        const float spacing = be_control_look->DefaultItemSpacing();
 
        BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
@@ -203,13 +199,7 @@ DesktopSettingsView::DesktopSettingsView()
                        .SetInsets(spacing * 2, 0, 0, 0)
                        .End()
                .AddGlue()
-               .AddGroup(B_HORIZONTAL)
-                       .Add(fMountButton)
-                       .AddGlue()
-                       .End()
                .SetInsets(spacing);
-
-       fMountButton->SetTarget(be_app);
 }
 
 
diff --git a/src/kits/tracker/SettingsViews.h b/src/kits/tracker/SettingsViews.h
index ce33283..be10b85 100644
--- a/src/kits/tracker/SettingsViews.h
+++ b/src/kits/tracker/SettingsViews.h
@@ -91,7 +91,6 @@ private:
        BRadioButton*   fMountVolumesOntoDesktopRadioButton;
        BCheckBox*              fMountSharedVolumesOntoDesktopCheckBox;
        BCheckBox*              fIntegrateNonBootBeOSDesktopsCheckBox;
-       BButton*                fMountButton;
 
        bool fShowDisksIcon;
        bool fMountVolumesOntoDesktop;
@@ -166,6 +165,47 @@ private:
        typedef SettingsView _inherited;
 };
 
+
+class AutomountSettingsPanel : public SettingsView {
+public:
+                                                               
AutomountSettingsPanel();
+       virtual                                         
~AutomountSettingsPanel();
+
+       virtual bool                            IsDefaultable() const;
+       virtual void                            Revert();
+       virtual void                            ShowCurrentSettings();
+       virtual void                            RecordRevertSettings();
+       virtual bool                            IsRevertable() const;
+
+protected:
+       virtual void                            MessageReceived(BMessage* 
message);
+       virtual void                            AttachedToWindow();
+
+private:
+                       void                            _SendSettings(bool 
rescan);
+                       void                            _GetSettings(BMessage* 
reply) const;
+                       void                            _ParseSettings(const 
BMessage& settings);
+
+                       BRadioButton*           fInitialDontMountCheck;
+                       BRadioButton*           fInitialMountAllBFSCheck;
+                       BRadioButton*           fInitialMountAllCheck;
+                       BRadioButton*           fInitialMountRestoreCheck;
+
+                       BRadioButton*           fScanningDisabledCheck;
+                       BRadioButton*           fAutoMountAllBFSCheck;
+                       BRadioButton*           fAutoMountAllCheck;
+
+                       BCheckBox*                      
fEjectWhenUnmountingCheckBox;
+
+                       BButton*                        fMountAllNow;
+
+                       BMessenger                      fTarget;
+                       BMessage                        fInitialSettings;
+
+                       typedef SettingsView _inherited;
+};
+
+
 } // namespace BPrivate
 
 using namespace BPrivate;
diff --git a/src/kits/tracker/Tracker.cpp b/src/kits/tracker/Tracker.cpp
index ea86a0e..a7e88d2 100644
--- a/src/kits/tracker/Tracker.cpp
+++ b/src/kits/tracker/Tracker.cpp
@@ -63,7 +63,6 @@ All rights reserved.
 
 #include "Attributes.h"
 #include "AutoLock.h"
-#include "AutoMounterSettings.h"
 #include "BackgroundImage.h"
 #include "Bitmaps.h"
 #include "Commands.h"
@@ -512,9 +511,6 @@ TTracker::MessageReceived(BMessage* message)
                        MountServer().SendMessage(message);
                        break;
 
-               case kRunAutomounterSettings:
-                       
AutomountSettingsDialog::RunAutomountSettings(MountServer());
-                       break;
 
                case kRestoreBackgroundImage:
                {
@@ -524,9 +520,14 @@ TTracker::MessageReceived(BMessage* message)
                        break;
                }
 
-               case kShowSettingsWindow:
-                       ShowSettingsWindow();
-                       break;
+               case kRunAutomounterSettings:
+                       ShowSettingsWindow();
+                       
fSettingsWindow->ShowPage(TrackerSettingsWindow::kAutomountSettings);
+                       break;
+
+               case kShowSettingsWindow:
+                       ShowSettingsWindow();
+                       break;
 
                case kFavoriteCountChangedExternally:
                        SendNotices(kFavoriteCountChangedExternally, message);
diff --git a/src/kits/tracker/TrackerSettingsWindow.cpp 
b/src/kits/tracker/TrackerSettingsWindow.cpp
index d9a26fa..9fc8fc6 100644
--- a/src/kits/tracker/TrackerSettingsWindow.cpp
+++ b/src/kits/tracker/TrackerSettingsWindow.cpp
@@ -114,11 +114,15 @@ TrackerSettingsWindow::TrackerSettingsWindow()
                .End();
 
        fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Desktop"),
-               new DesktopSettingsView()));
+               new DesktopSettingsView()), kDesktopSettings);
        fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Windows"),
-               new WindowsSettingsView()));
+               new WindowsSettingsView()), kWindowsSettings);
        fSettingsTypeListView->AddItem(new SettingsItem(
-               B_TRANSLATE("Volume icons"), new SpaceBarSettingsView()));
+               B_TRANSLATE("Volume icons"), new SpaceBarSettingsView()),
+               kSpaceBarSettings);
+       fSettingsTypeListView->AddItem(new SettingsItem(
+               B_TRANSLATE("Disk mount"), new AutomountSettingsPanel()),
+               kAutomountSettings);
 
        // constraint the listview width so that the longest item fits
        float width = 0;
@@ -198,6 +202,13 @@ TrackerSettingsWindow::Show()
 }
 
 
+void
+TrackerSettingsWindow::ShowPage(SettingsPage page)
+{
+       fSettingsTypeListView->Select(page);
+}
+
+
 SettingsView*
 TrackerSettingsWindow::_ViewAt(int32 i)
 {
diff --git a/src/kits/tracker/TrackerSettingsWindow.h 
b/src/kits/tracker/TrackerSettingsWindow.h
index 522817d..3f8cbef 100644
--- a/src/kits/tracker/TrackerSettingsWindow.h
+++ b/src/kits/tracker/TrackerSettingsWindow.h
@@ -54,6 +54,15 @@ public:
        void MessageReceived(BMessage* message);
        void Show();
 
+       enum SettingsPage {
+               kDesktopSettings,
+               kWindowsSettings,
+               kSpaceBarSettings,
+               kAutomountSettings
+       };
+
+       void ShowPage(SettingsPage page);
+
 private:
        SettingsView* _ViewAt(int32 i);
 


Other related posts:

  • » [haiku-commits] haiku: hrev47503 - src/kits/tracker - pulkomandy