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.
This commit is contained in:
Adrien Destugues
2014-07-16 14:46:27 +02:00
parent 62f70e6f0a
commit dd03c93fbf
7 changed files with 157 additions and 193 deletions
+85 -113
View File
@@ -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,37 +149,11 @@ 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
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);
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);
ShowCurrentSettings();
}
@@ -229,6 +162,48 @@ AutomountSettingsPanel::~AutomountSettingsPanel()
}
bool
AutomountSettingsPanel::IsDefaultable() const
{
return false;
}
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);
}
void
AutomountSettingsPanel::AttachedToWindow()
{
@@ -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;
}
(new AutomountSettingsDialog(&reply, target))->Show();
}
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);
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);
}
-59
View File
@@ -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
-10
View File
@@ -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);
}
+41 -1
View File
@@ -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;
+8 -7
View File
@@ -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);
+14 -3
View File
@@ -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)
{
+9
View File
@@ -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);