* Cleanup, some style changes.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35076 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2010-01-14 21:21:45 +00:00
parent c6aa013564
commit 35c09220cc
2 changed files with 121 additions and 92 deletions
+65 -47
View File
@@ -9,6 +9,7 @@
#include "ExpanderThread.h" #include "ExpanderThread.h"
#include "ExpanderPreferences.h" #include "ExpanderPreferences.h"
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Box.h> #include <Box.h>
@@ -24,19 +25,24 @@
#include <StringView.h> #include <StringView.h>
#include <TextView.h> #include <TextView.h>
const uint32 MSG_SOURCE = 'mSOU';
const uint32 MSG_DEST = 'mDES'; const uint32 MSG_SOURCE = 'mSOU';
const uint32 MSG_EXPAND = 'mEXP'; const uint32 MSG_DEST = 'mDES';
const uint32 MSG_SHOW = 'mSHO'; const uint32 MSG_EXPAND = 'mEXP';
const uint32 MSG_STOP = 'mSTO'; const uint32 MSG_SHOW = 'mSHO';
const uint32 MSG_PREFERENCES = 'mPRE'; const uint32 MSG_STOP = 'mSTO';
const uint32 MSG_SOURCETEXT = 'mSTX'; const uint32 MSG_PREFERENCES = 'mPRE';
const uint32 MSG_DESTTEXT = 'mDTX'; const uint32 MSG_SOURCETEXT = 'mSTX';
const uint32 MSG_SHOWCONTENTS = 'mSCT'; const uint32 MSG_DESTTEXT = 'mDTX';
const uint32 MSG_SHOWCONTENTS = 'mSCT';
ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref *ref, BMessage *settings) ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
: BWindow(frame, "Expander", B_TITLED_WINDOW, B_NOT_ZOOMABLE), BMessage* settings)
:
BWindow(frame, "Expander", B_TITLED_WINDOW, B_NOT_ZOOMABLE),
fSourcePanel(NULL),
fDestPanel(NULL),
fSourceChanged(true), fSourceChanged(true),
fListingThread(NULL), fListingThread(NULL),
fListingStarted(false), fListingStarted(false),
@@ -45,22 +51,24 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref *ref, BMessage *sett
fSettings(*settings), fSettings(*settings),
fPreferences(NULL) fPreferences(NULL)
{ {
fSourcePanel = NULL;
fDestPanel = NULL;
// create menu bar // create menu bar
fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar"); fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar");
BMenu *menu = new BMenu("File"); BMenu* menu = new BMenu("File");
BMenuItem *item; BMenuItem* item;
menu->AddItem(item = new BMenuItem("About Expander" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); menu->AddItem(item = new BMenuItem("About Expander" B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
item->SetTarget(be_app_messenger); item->SetTarget(be_app_messenger);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(fSourceItem = new BMenuItem("Set source" B_UTF8_ELLIPSIS, new BMessage(MSG_SOURCE), 'O')); menu->AddItem(fSourceItem = new BMenuItem("Set source" B_UTF8_ELLIPSIS,
menu->AddItem(fDestItem = new BMenuItem("Set destination" B_UTF8_ELLIPSIS, new BMessage(MSG_DEST), 'D')); new BMessage(MSG_SOURCE), 'O'));
menu->AddItem(fDestItem = new BMenuItem("Set destination" B_UTF8_ELLIPSIS,
new BMessage(MSG_DEST), 'D'));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(fExpandItem = new BMenuItem("Expand", new BMessage(MSG_EXPAND), 'E')); menu->AddItem(fExpandItem = new BMenuItem("Expand", new BMessage(MSG_EXPAND),
'E'));
fExpandItem->SetEnabled(false); fExpandItem->SetEnabled(false);
menu->AddItem(fShowItem = new BMenuItem("Show contents", new BMessage(MSG_SHOW), 'L')); menu->AddItem(fShowItem = new BMenuItem("Show contents",
new BMessage(MSG_SHOW), 'L'));
fShowItem->SetEnabled(false); fShowItem->SetEnabled(false);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(fStopItem = new BMenuItem("Stop", new BMessage(MSG_STOP), 'K')); menu->AddItem(fStopItem = new BMenuItem("Stop", new BMessage(MSG_STOP), 'K'));
@@ -77,7 +85,7 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref *ref, BMessage *sett
BRect rect = Bounds(); BRect rect = Bounds();
rect.top += fBar->Bounds().Height() + 1; rect.top += fBar->Bounds().Height() + 1;
BView *topView = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW); BView* topView = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView); AddChild(topView);
@@ -179,13 +187,14 @@ ExpanderWindow::~ExpanderWindow()
delete fSourcePanel; delete fSourcePanel;
} }
bool bool
ExpanderWindow::ValidateDest() ExpanderWindow::ValidateDest()
{ {
BEntry entry(fDestText->Text(), true); BEntry entry(fDestText->Text(), true);
BVolume volume; BVolume volume;
if (!entry.Exists()) { if (!entry.Exists()) {
BAlert *alert = new BAlert("destAlert", "The destination" BAlert* alert = new BAlert("destAlert", "The destination"
" folder does not exist.", "Cancel", NULL, NULL, " folder does not exist.", "Cancel", NULL, NULL,
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT);
alert->Go(); alert->Go();
@@ -206,6 +215,7 @@ ExpanderWindow::ValidateDest()
} }
} }
void void
ExpanderWindow::FrameResized(float width, float height) ExpanderWindow::FrameResized(float width, float height)
{ {
@@ -220,7 +230,7 @@ ExpanderWindow::FrameResized(float width, float height)
void void
ExpanderWindow::MessageReceived(BMessage *msg) ExpanderWindow::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case MSG_SOURCE: case MSG_SOURCE:
@@ -238,6 +248,7 @@ ExpanderWindow::MessageReceived(BMessage *msg)
fSourcePanel->Show(); fSourcePanel->Show();
break; break;
} }
case MSG_DEST: case MSG_DEST:
{ {
BEntry entry(fDestText->Text(), true); BEntry entry(fDestText->Text(), true);
@@ -246,13 +257,15 @@ ExpanderWindow::MessageReceived(BMessage *msg)
entry.GetRef(&destRef); entry.GetRef(&destRef);
if (!fDestPanel) { if (!fDestPanel) {
BMessenger messenger(this); BMessenger messenger(this);
fDestPanel = new DirectoryFilePanel(B_OPEN_PANEL, &messenger, &destRef, fDestPanel = new DirectoryFilePanel(B_OPEN_PANEL, &messenger,
B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter(), true); &destRef, B_DIRECTORY_NODE, false, NULL,
new DirectoryRefFilter(), true);
} else } else
fDestPanel->SetPanelDirectory(&destRef); fDestPanel->SetPanelDirectory(&destRef);
fDestPanel->Show(); fDestPanel->Show();
break; break;
} }
case MSG_DIRECTORY: case MSG_DIRECTORY:
{ {
entry_ref ref; entry_ref ref;
@@ -281,8 +294,9 @@ ExpanderWindow::MessageReceived(BMessage *msg)
case MSG_STOP: case MSG_STOP:
if (fExpandingStarted) { if (fExpandingStarted) {
fExpandingThread->SuspendExternalExpander(); fExpandingThread->SuspendExternalExpander();
BAlert *alert = new BAlert("stopAlert", "Are you sure you want to stop expanding this\n" BAlert* alert = new BAlert("stopAlert", "Are you sure you want "
"archive? The expanded items may not be complete.", "Stop", "Continue", NULL, "to stop expanding this\narchive? The expanded items may "
"not be complete.", "Stop", "Continue", NULL,
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT);
if (alert->Go() == 0) { if (alert->Go() == 0) {
fExpandingThread->ResumeExternalExpander(); fExpandingThread->ResumeExternalExpander();
@@ -314,7 +328,7 @@ ExpanderWindow::MessageReceived(BMessage *msg)
{ {
BEntry entry(fSourceText->Text(), true); BEntry entry(fSourceText->Text(), true);
if (!entry.Exists()) { if (!entry.Exists()) {
BAlert *alert = new BAlert("srcAlert", "The file doesn't exist", BAlert* alert = new BAlert("srcAlert", "The file doesn't exist",
"Cancel", NULL, NULL, "Cancel", NULL, NULL,
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT);
alert->Go(); alert->Go();
@@ -323,7 +337,7 @@ ExpanderWindow::MessageReceived(BMessage *msg)
entry_ref ref; entry_ref ref;
entry.GetRef(&ref); entry.GetRef(&ref);
ExpanderRule *rule = fRules.MatchingRule(&ref); ExpanderRule* rule = fRules.MatchingRule(&ref);
if (rule) { if (rule) {
fSourceChanged = true; fSourceChanged = true;
fSourceRef = ref; fSourceRef = ref;
@@ -337,8 +351,8 @@ ExpanderWindow::MessageReceived(BMessage *msg)
BString string = "The file : "; BString string = "The file : ";
string += fSourceText->Text(); string += fSourceText->Text();
string += " is not supported"; string += " is not supported";
BAlert *alert = new BAlert("srcAlert", string.String(), BAlert* alert = new BAlert("srcAlert", string.String(), "Cancel",
"Cancel", NULL, NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT); NULL, NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT);
alert->Go(); alert->Go();
fShowContents->SetEnabled(false); fShowContents->SetEnabled(false);
@@ -347,16 +361,17 @@ ExpanderWindow::MessageReceived(BMessage *msg)
fShowItem->SetEnabled(false); fShowItem->SetEnabled(false);
} }
break; break;
case MSG_DESTTEXT: case MSG_DESTTEXT:
{
ValidateDest(); ValidateDest();
} break;
break;
case MSG_PREFERENCES: case MSG_PREFERENCES:
if (!fPreferences) if (!fPreferences)
fPreferences = new ExpanderPreferences(&fSettings); fPreferences = new ExpanderPreferences(&fSettings);
fPreferences->Show(); fPreferences->Show();
break; break;
case 'outp': case 'outp':
if (!fExpandingStarted && fListingStarted) { if (!fExpandingStarted && fListingStarted) {
BString string; BString string;
@@ -372,9 +387,10 @@ ExpanderWindow::MessageReceived(BMessage *msg)
} }
fListingText->ScrollToSelection(); fListingText->ScrollToSelection();
} }
break; break;
case 'exit': // thread has finished (finished, quit, killed, we don't know)
case 'exit':
// thread has finished (finished, quit, killed, we don't know)
// reset window state // reset window state
if (fExpandingStarted) { if (fExpandingStarted) {
fStatusView->SetText("File expanded"); fStatusView->SetText("File expanded");
@@ -390,12 +406,14 @@ ExpanderWindow::MessageReceived(BMessage *msg)
} else } else
fStatusView->SetText(""); fStatusView->SetText("");
break; break;
case 'exrr': // thread has finished case 'exrr': // thread has finished
// reset window state // reset window state
fStatusView->SetText("Error when expanding archive"); fStatusView->SetText("Error when expanding archive");
CloseWindowOrKeepOpen(); CloseWindowOrKeepOpen();
break; break;
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
@@ -412,9 +430,10 @@ ExpanderWindow::CanQuit()
if (fExpandingStarted) { if (fExpandingStarted) {
fExpandingThread->SuspendExternalExpander(); fExpandingThread->SuspendExternalExpander();
BAlert *alert = new BAlert("stopAlert", "Are you sure you want to stop expanding this\n" BAlert* alert = new BAlert("stopAlert", "Are you sure you want to stop "
"archive? The expanded items may not be complete.", "Stop", "Continue", NULL, "expanding this\narchive? The expanded items may not be complete.",
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); "Stop", "Continue", NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING,
B_WARNING_ALERT);
if (alert->Go() == 0) { if (alert->Go() == 0) {
fExpandingThread->ResumeExternalExpander(); fExpandingThread->ResumeExternalExpander();
StopExpanding(); StopExpanding();
@@ -444,7 +463,7 @@ ExpanderWindow::QuitRequested()
void void
ExpanderWindow::RefsReceived(BMessage *msg) ExpanderWindow::RefsReceived(BMessage* msg)
{ {
entry_ref ref; entry_ref ref;
int32 i = 0; int32 i = 0;
@@ -502,15 +521,14 @@ ExpanderWindow::RefsReceived(BMessage *msg)
void void
ExpanderWindow::StartExpanding() ExpanderWindow::StartExpanding()
{ {
ExpanderRule *rule = fRules.MatchingRule(&fSourceRef); ExpanderRule* rule = fRules.MatchingRule(&fSourceRef);
if (!rule) if (!rule)
return; return;
BEntry destEntry(fDestText->Text(), true); BEntry destEntry(fDestText->Text(), true);
if (!destEntry.Exists()) { if (!destEntry.Exists()) {
BAlert *alert = new BAlert("destAlert", "The folder was either moved, renamed or not\n" BAlert* alert = new BAlert("destAlert", "The folder was either moved, "
"supported.", "renamed or not\nsupported.", "Cancel", NULL, NULL,
"Cancel", NULL, NULL,
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT);
alert->Go(); alert->Go();
return; return;
@@ -607,7 +625,7 @@ ExpanderWindow::StartListing()
if (!fSourceChanged) if (!fSourceChanged)
return; return;
ExpanderRule *rule = fRules.MatchingRule(&fSourceRef); ExpanderRule* rule = fRules.MatchingRule(&fSourceRef);
if (!rule) if (!rule)
return; return;
@@ -690,7 +708,7 @@ ExpanderWindow::OpenDestFolder()
if (!openFolder) if (!openFolder)
return; return;
BMessage * message = new BMessage(B_REFS_RECEIVED); BMessage* message = new BMessage(B_REFS_RECEIVED);
message->AddRef("refs", &fDestRef); message->AddRef("refs", &fDestRef);
BPath path(&fDestRef); BPath path(&fDestRef);
BMessenger tracker("application/x-vnd.Be-TRAK"); BMessenger tracker("application/x-vnd.Be-TRAK");
+56 -45
View File
@@ -9,10 +9,12 @@
#define EXPANDER_WINDOW_H #define EXPANDER_WINDOW_H
#include <Window.h>
#include "DirectoryFilePanel.h" #include "DirectoryFilePanel.h"
#include "ExpanderRules.h" #include "ExpanderRules.h"
#include <Window.h>
class BCheckBox; class BCheckBox;
class BMenu; class BMenu;
@@ -26,59 +28,68 @@ class ExpanderPreferences;
class ExpanderWindow : public BWindow { class ExpanderWindow : public BWindow {
public: public:
ExpanderWindow(BRect frameRect, const entry_ref *ref, BMessage *settings); ExpanderWindow(BRect frameRect,
virtual ~ExpanderWindow(); const entry_ref* ref, BMessage* settings);
virtual ~ExpanderWindow();
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage* msg);
virtual bool QuitRequested(); virtual bool QuitRequested();
void SetRef(const entry_ref *ref); void SetRef(const entry_ref* ref);
void RefsReceived(BMessage *msg); void RefsReceived(BMessage* msg);
private: private:
bool CanQuit(); bool CanQuit();
// returns true if the window can be closed safely, false if not // returns true if the window can be closed safely, false if not
void CloseWindowOrKeepOpen(); void CloseWindowOrKeepOpen();
void OpenDestFolder(); void OpenDestFolder();
void AutoListing(); void AutoListing();
void AutoExpand(); void AutoExpand();
void StartExpanding(); void StartExpanding();
void StopExpanding(); void StopExpanding();
void _UpdateWindowSize(bool showContents); void _UpdateWindowSize(bool showContents);
void StartListing(); void StartListing();
void StopListing(); void StopListing();
bool ValidateDest(); bool ValidateDest();
BFilePanel *fSourcePanel; private:
DirectoryFilePanel *fDestPanel; BFilePanel* fSourcePanel;
BMenuBar *fBar; DirectoryFilePanel* fDestPanel;
BMenu *fMenu; BMenuBar* fBar;
entry_ref fSourceRef; BMenu* fMenu;
entry_ref fDestRef; entry_ref fSourceRef;
bool fSourceChanged; entry_ref fDestRef;
bool fSourceChanged;
BButton *fSourceButton, *fDestButton, *fExpandButton; BButton* fSourceButton;
BMenuItem *fExpandItem, *fShowItem, *fStopItem, BButton* fDestButton;
*fSourceItem, *fDestItem, *fPreferencesItem; BButton* fExpandButton;
BCheckBox *fShowContents; BMenuItem* fExpandItem;
BTextControl *fSourceText, *fDestText; BMenuItem* fShowItem;
BStringView* fStatusView; BMenuItem* fStopItem;
BTextView *fListingText; BMenuItem* fSourceItem;
BScrollView *fListingScroll; BMenuItem* fDestItem;
BMenuItem* fPreferencesItem;
BCheckBox* fShowContents;
BTextControl* fSourceText;
BTextControl* fDestText;
BStringView* fStatusView;
BTextView* fListingText;
BScrollView* fListingScroll;
ExpanderThread *fListingThread; ExpanderThread* fListingThread;
bool fListingStarted; bool fListingStarted;
ExpanderThread *fExpandingThread; ExpanderThread* fExpandingThread;
bool fExpandingStarted; bool fExpandingStarted;
BMessage fSettings; BMessage fSettings;
ExpanderPreferences *fPreferences; ExpanderPreferences* fPreferences;
ExpanderRules fRules; ExpanderRules fRules;
float fLargestDelta; float fLargestDelta;
}; };
#endif /* EXPANDER_WINDOW_H */ #endif /* EXPANDER_WINDOW_H */