From 55a5a6bdfa5537e5422bf6ef0b1800537f981066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 16 Mar 2004 10:28:03 +0000 Subject: [PATCH] Initial checkin of the Expander replacement app. Redone from scratch because we don't have Dan Lee's code. Beta version. Testing is welcome. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7001 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/expander/DirectoryFilePanel.cpp | 89 ++++ src/apps/expander/DirectoryFilePanel.h | 59 ++ src/apps/expander/Expander.rdef | 355 ++++++++++++ src/apps/expander/ExpanderApp.cpp | 115 ++++ src/apps/expander/ExpanderApp.h | 52 ++ src/apps/expander/ExpanderPreferences.cpp | 267 ++++++++++ src/apps/expander/ExpanderPreferences.h | 57 ++ src/apps/expander/ExpanderRules.cpp | 180 +++++++ src/apps/expander/ExpanderRules.h | 78 +++ src/apps/expander/ExpanderSettings.cpp | 212 ++++++++ src/apps/expander/ExpanderSettings.h | 52 ++ src/apps/expander/ExpanderThread.cpp | 276 ++++++++++ src/apps/expander/ExpanderThread.h | 81 +++ src/apps/expander/ExpanderWindow.cpp | 623 ++++++++++++++++++++++ src/apps/expander/ExpanderWindow.h | 94 ++++ src/apps/expander/GenericThread.cpp | 386 ++++++++++++++ src/apps/expander/GenericThread.h | 83 +++ src/apps/expander/Jamfile | 16 + 18 files changed, 3075 insertions(+) create mode 100644 src/apps/expander/DirectoryFilePanel.cpp create mode 100644 src/apps/expander/DirectoryFilePanel.h create mode 100644 src/apps/expander/Expander.rdef create mode 100644 src/apps/expander/ExpanderApp.cpp create mode 100644 src/apps/expander/ExpanderApp.h create mode 100644 src/apps/expander/ExpanderPreferences.cpp create mode 100644 src/apps/expander/ExpanderPreferences.h create mode 100644 src/apps/expander/ExpanderRules.cpp create mode 100644 src/apps/expander/ExpanderRules.h create mode 100644 src/apps/expander/ExpanderSettings.cpp create mode 100644 src/apps/expander/ExpanderSettings.h create mode 100644 src/apps/expander/ExpanderThread.cpp create mode 100644 src/apps/expander/ExpanderThread.h create mode 100644 src/apps/expander/ExpanderWindow.cpp create mode 100644 src/apps/expander/ExpanderWindow.h create mode 100644 src/apps/expander/GenericThread.cpp create mode 100644 src/apps/expander/GenericThread.h create mode 100644 src/apps/expander/Jamfile diff --git a/src/apps/expander/DirectoryFilePanel.cpp b/src/apps/expander/DirectoryFilePanel.cpp new file mode 100644 index 0000000000..44549836ab --- /dev/null +++ b/src/apps/expander/DirectoryFilePanel.cpp @@ -0,0 +1,89 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// DirectoryFilePanel.cpp +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#include "DirectoryFilePanel.h" +#include +#include + +DirectoryRefFilter::DirectoryRefFilter() + : BRefFilter() +{ +} + + +bool +DirectoryRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat *st, + const char *filetype) +{ + return (node->IsDirectory()); +} + + +DirectoryFilePanel::DirectoryFilePanel(file_panel_mode mode, BMessenger *target, + const entry_ref *start_directory, uint32 node_flavors, + bool allow_multiple_selection, BMessage *message, BRefFilter *filter, + bool modal, bool hide_when_done) + :BFilePanel(mode,target,start_directory, node_flavors, + allow_multiple_selection,message,filter,modal,hide_when_done), + fCurrentButton(NULL) +{ +} + + +void +DirectoryFilePanel::Show() +{ + if (!fCurrentButton) { + entry_ref ref; + char label[50]; + GetPanelDirectory(&ref); + sprintf(label, "Select '%s'", ref.name); + Window()->Lock(); + BView *background = Window()->ChildAt(0); + fCurrentButton = new BButton( + BRect(113, background->Bounds().bottom-35, 269, background->Bounds().bottom-10), + "directoryButton", label, new BMessage(MSG_DIRECTORY), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); + background->AddChild(fCurrentButton); + SetButtonLabel(B_DEFAULT_BUTTON, "Select"); + fCurrentButton->SetTarget(Messenger()); + Window()->Unlock(); + } + BFilePanel::Show(); +} + +void +DirectoryFilePanel::SelectionChanged(void) +{ + entry_ref ref; + char label[50]; + GetPanelDirectory(&ref); + Window()->Lock(); + sprintf(label, "Select '%s'", ref.name); + fCurrentButton->SetLabel(label); + Window()->Unlock(); + BFilePanel::SelectionChanged(); +} diff --git a/src/apps/expander/DirectoryFilePanel.h b/src/apps/expander/DirectoryFilePanel.h new file mode 100644 index 0000000000..5e53dcf2fd --- /dev/null +++ b/src/apps/expander/DirectoryFilePanel.h @@ -0,0 +1,59 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// DirectoryFilePanel.h +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#ifndef _DirectoryFilePanel_h +#define _DirectoryFilePanel_h + +#include +#include + +const uint32 MSG_DIRECTORY = 'mDIR'; + + +class DirectoryRefFilter : public BRefFilter { + public: + DirectoryRefFilter(); + bool Filter(const entry_ref *ref, BNode* node, struct stat *st, + const char *filetype); +}; + + +class DirectoryFilePanel : public BFilePanel { + public: + DirectoryFilePanel(file_panel_mode mode = B_OPEN_PANEL, + BMessenger *target = 0, const entry_ref *start_directory = 0, + uint32 node_flavors = 0, bool allow_multiple_selection = true, + BMessage *message = 0, BRefFilter * = 0, + bool modal = false, bool hide_when_done = true); + virtual void SelectionChanged(void); + virtual void Show(); + + protected: + BButton *fCurrentButton; +}; + +#endif \ No newline at end of file diff --git a/src/apps/expander/Expander.rdef b/src/apps/expander/Expander.rdef new file mode 100644 index 0000000000..14091af576 --- /dev/null +++ b/src/apps/expander/Expander.rdef @@ -0,0 +1,355 @@ + +resource large_icon +{ + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF001A191A0800FFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00191A3F1111080002FFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00191A3F3F1108090000FFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0004193F3F11080200AAFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003F3F020202020202AA00FFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF02023F3F3F3F111102AA00FFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFF000000000000000000020202020202AA00FFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFF00F9F9F9F9F9F9F90000000A0B080B0000FFFFFFFF" + $"FFFFFFFF0000000000000000F9F9F900F900F9003F1100000000AA0000FFFFFF" + $"FFFFFFFF005A5A5A5A5A5A00F9F900F900F9F9003F3F3F3F111111111100FFFF" + $"FFFFFFFF005A5A5A5A5A5A00F9F900000000F9003F3F3F3F3F3F3F3F171100FF" + $"FFFFFFFF005A5A5A005A5A00F9F9F9F9F9F9F9003F3F3F3F3F17003F3F1100FF" + $"FFFFFF00005A5A005A005A5A00F9F9000000F9F9003F113F1700003F1100FFFF" + $"FFFF0083005A5A000000005A00F900F900F9F9F9003F1111003FAA001100FFFF" + $"FF00838383005A5A5A5A5A5A00F9F9000000F9F9003F1100D9D95BAA00FFFFFF" + $"0083838383005A000000005A00F9F9F9F9F9F9F90000005BD95B0100FFFFFFFF" + $"0000838383005A5A5A5A5A5A00F900F9F9F9F9F900D95B5B5B018D8D00FFFFFF" + $"00D9000083005A00005A5A00F9F900000000F9F900D9D900008DB48D01FFFFFF" + $"003FD93F00005A005A5A0000F9F900F9F9F9F9001CD95B008D8D66B400FFFFFF" + $"00D9D9D9D9D900005A000000F9F9F9F9F9F9F900000000006666668D01FFFFFF" + $"00D93FD93FD93FD90000D9000000000000000000008D8D006666668D00FFFFFF" + $"0083D9D9D9D9D9D900D93FD9838300FFFFFFFFFF00668D006666668D00FFFFFF" + $"00D98383D9D93FD9003FD983838300FFFFFFFFFF00668D006666668D00FFFFFF" + $"00D9D9D98383D9D900D98383838300FFFFFFFFFF008D8D006666668D00FFFFFF" + $"00D9D9D9D9D9838300838383838300FFFFFFFFFF006666008D66668D00FFFFFF" + $"00D9D9D9D9D9D9D9838383838300FFFFFFFFFFFF00000000668D8D0000FFFFFF" + $"00D9D9D9D9D9D9D98383838300FFFFFFFFFFFF0000AA000000668D00FFFFFFFF" + $"0000D9D9D9D9D9D983838300FFFFFFFFFFFFFF00AA00AA00AA000000FFFFFFFF" + $"FFFF0000D9D9D9D9838300FFFFFFFFFFFFFF00AA00000083AAAA00FFFFFFFFFF" + $"FFFFFFFF0000D9D98300FFFFFFFFFFFFFFFF0000AA0083AAAA0000FFFFFFFFFF" + $"FFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFF0000000000FFFFFFFFFFFFFF" +}; + +resource mini_icon +{ + $"FFFFFFFFFFFFFFFFFFFF00000000FFFF" + $"FFFFFFFFFFFFFFFFFF00083F110800FF" + $"FFFFFFFFFFFFFFFFFF000811090000FF" + $"FFFFFFFFFFFFFFFFFF0019111100AAFF" + $"FFFFFFFFFFFFFFFFFFFF000000AA00FF" + $"FFFFFFFFFFFF00000000003F11111100" + $"FFFF0000000000F9F9F9001100D91100" + $"FF00005A5A0000F9F9F90000D90000FF" + $"0083005A5A0000F9F9F900D9000000FF" + $"0000D95A5A0000F9F900D90000B400FF" + $"003F00D9003F00000000008D008D00FF" + $"0083D9003FD900FFFFFF008D008D00FF" + $"00D98300D98300FFFFFF008D008D00FF" + $"00D9D9D9838300FFFFFF0000000000FF" + $"0000D9D98300FFFFFF00AA00AA00FFFF" + $"FFFF000000FFFFFFFF0000000000FFFF" +}; + +resource app_signature "application/x-vnd.obos-Expander"; + +resource app_version +{ + short_info = "OBOS-Expander", + long_info = "OpenBeOS version of Expander" +}; + +resource app_flags B_SINGLE_LAUNCH; + +resource(0, "BEOS:L:application/x-gzip") #'ICON' array +{ + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFF00000000000000FF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF006F6F6F00000000006F6F6F6F6F6F00FF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF006F6F6F6F6F6F6F6F6F6F6F6F6F6F00FF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF006F6F00006F00006F006F00006F6F00FF" + $"FFFFFFFFFFFFFFFFFFFFFFFF000000006F006F6F6F6F006F006F006F006F00FF" + $"FFFFFFFFFFFFFFFFFFFF00003FD93F006F006F006F006F6F006F00006F6F00FF" + $"FFFFFFFFFFFFFFFFFF00D93FD93FD9006F0000006F00006F006F006F6F6F00FF" + $"FFFFFFFFFFFFFFFF00D93FD93FD93F006F6F6F6F6F6F6F6F6F6F6F6F6F6F00FF" + $"FFFFFFFFFFFFFF00D93FD93FD93FD90000006F6F6F6F6F6F00000000000000FF" + $"FFFFFFFFFFFF00D93FD93FD93FD93F003FD90000000000000000FFFFFFFFFFFF" + $"FFFFFFFFFF000000D93FD93FD93FD900D93F003FD93FD93FD93F0000FFFFFFFF" + $"FFFFFFFF00D93FD900000000000000003F003FD93FD93FD93FD93FD900FFFFFF" + $"FFFFFF00D93FD93FD9000000D93F0000003FD93FD93FD93FD93FD93FD900FFFF" + $"FFFF00D93FD93FD93F003FD900003F000000000000003FD93FD93FD93FD900FF" + $"FF00D93FD93FD93FD93F0000003F0000003FD93FD93F003FD93FD93FD98300FF" + $"FF003FD93FD93FD93FD93FD93F003FD900003FD900003FD93FD93FD9838300FF" + $"00D9D93FD93FD93FD93FD93F003FD900D9000000003FD93FD93FD983838300FF" + $"00D9D9D93FD93FD93FD93F003FD93F003FD93FD93F0000D93FD98383838300FF" + $"00D9D9D9D9D9D93FD93F003FD93FD900D93FD93FD93FD900008383838300FFFF" + $"FF00D9D9D9D9D9D93F003FD93FD93FD93FD93FD93FD93FD90083838300FFFFFF" + $"FFFF0000D9D9D9D9D901D93FD93FD93FD93FD93FD93FD98300838300FFFFFFFF" + $"FFFFFFFF0000D9D9D901D9D93FD93FD93FD93FD93FD98383008300FFFFFFFFFF" + $"FFFFFFFFFFFF0000D900D9D9D9D9D93FD93FD93FD98383830000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000D9D9D9D9D9D93FD93FD98383838300FFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF0000D9D9D9D9D9D9D98383838301FFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF0000D9D9D9D98383838301FFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFF0000D9D983830100FFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(1, "BEOS:L:application/x-tar") #'ICON' array +{ + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFF000000000000FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF005A5A5A00000000005A5A5A5A5A01FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF005A5A5A5A5A5A5A5A5A5A5A5A5A01FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF005A0000005A5A005A5A00005A5A00FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF000000005A5A005A5A005A005A005A005A01FFFF" + $"FFFFFFFFFFFFFFFFFFFF00003FD93F005A5A005A5A0000005A00005A5A00FFFF" + $"FFFFFFFFFFFFFFFFFF00D93FD93FD9005A5A005A5A005A005A005A015A00FFFF" + $"FFFFFFFFFFFFFFFF00D93FD93FD93F005A5A5A5A5A5A5A5A5A5A5A5A5A01FFFF" + $"FFFFFFFFFFFFFF00D93FD93FD93FD90000005A5A5A5A5A5A000000000000FFFF" + $"FFFFFFFFFFFF00D93FD93FD93FD93F003FD90000000000000000FFFFFFFFFFFF" + $"FFFFFFFFFF000000D93FD93FD93FD900D93F003FD93FD93FD93F0000FFFFFFFF" + $"FFFFFFFF00D93FD900000000000000003F003FD93FD93FD93FD93FD900FFFFFF" + $"FFFFFF00D93FD93FD9000000D93F0000003FD93FD93FD93FD93FD93FD900FFFF" + $"FFFF00D93FD93FD93F003FD900003F000000000000003FD93FD93FD93FD900FF" + $"FF00D93FD93FD93FD93F0000003F0000003FD93FD93F003FD93FD93FD98300FF" + $"FF003FD93FD93FD93FD93FD93F003FD900003FD900003FD93FD93FD9838300FF" + $"00D9D93FD93FD93FD93FD93F003FD900D9000000003FD93FD93FD983838300FF" + $"00D9D9D93FD93FD93FD93F003FD93F003FD93FD93F0000D93FD98383838300FF" + $"00D9D9D9D9D9D93FD93F003FD93FD900D93FD93FD93FD9000083838383000FFF" + $"FF00D9D9D9D9D9D93F003FD93FD93FD93FD93FD93FD93FD900838383000FFFFF" + $"FFFF0000D9D9D9D9D901D93FD93FD93FD93FD93FD93FD983008383000FFFFFFF" + $"FFFFFFFF0000D9D9D901D9D93FD93FD93FD93FD93FD983830083000FFFFFFFFF" + $"FFFFFFFFFFFF0000D900D9D9D9D9D93FD93FD93FD983838300000FFFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000D9D9D9D9D9D93FD93FD983838383000FFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF0000D9D9D9D9D9D9D983838383010FFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF0000D9D9D9D983838383010FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFF0000D9D983830100FFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(2, "BEOS:L:application/x-zip-compressed") #'ICON' array +{ + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFF000000000000FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00F9F9F90000000000F9F9F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00F9F9F9F9F9F9F9F9F9F9F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00F9F9000000F900F90000F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF00000000F9F9F9F900F900F900F900F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFF00003FD93F00F9F9F900F9F900F90000F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFF00D93FD93FD900F9F9000000F900F900F9F9F9F900FFFF" + $"FFFFFFFFFFFFFFFF00D93FD93FD93F00F9F9F9F9F9F9F9F9F9F9F9F9F900FFFF" + $"FFFFFFFFFFFFFF00D93FD93FD93FD9000000F9F9F9F9F9F9000000000000FFFF" + $"FFFFFFFFFFFF00D93FD93FD93FD93F003FD90000000000000000FFFFFFFFFFFF" + $"FFFFFFFFFF000000D93FD93FD93FD900D93F003FD93FD93FD93F0000FFFFFFFF" + $"FFFFFFFF00D93FD900000000000000003F003FD93FD93FD93FD93FD900FFFFFF" + $"FFFFFF00D93FD93FD9000000D93F0000003FD93FD93FD93FD93FD93FD900FFFF" + $"FFFF00D93FD93FD93F003FD900003F000000000000003FD93FD93FD93FD900FF" + $"FF00D93FD93FD93FD93F0000003F0000003FD93FD93F003FD93FD93FD98300FF" + $"FF003FD93FD93FD93FD93FD93F003FD900003FD900003FD93FD93FD9838300FF" + $"00D9D93FD93FD93FD93FD93F003FD900D9000000003FD93FD93FD983838300FF" + $"00D9D9D93FD93FD93FD93F003FD93F003FD93FD93F0000D93FD98383838300FF" + $"00D9D9D9D9D9D93FD93F003FD93FD900D93FD93FD93FD9000083838383000FFF" + $"FF00D9D9D9D9D9D93F003FD93FD93FD93FD93FD93FD93FD900838383000FFFFF" + $"FFFF0000D9D9D9D9D901D93FD93FD93FD93FD93FD93FD983008383000FFFFFFF" + $"FFFFFFFF0000D9D9D901D9D93FD93FD93FD93FD93FD983830083000FFFFFFFFF" + $"FFFFFFFFFFFF0000D900D9D9D9D9D93FD93FD93FD983838300000FFFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000D9D9D9D9D9D93FD93FD983838383000FFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF0000D9D9D9D9D9D9D983838383010FFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF0000D9D9D9D983838383010FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFF0000D9D9838301000EFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(3, "BEOS:L:application/zip") #'ICON' array +{ + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFF000000000000FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00F9F9F90000000000F9F9F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00F9F9F9F9F9F9F9F9F9F9F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00F9F9000000F900F90000F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF00000000F9F9F9F900F900F900F900F9F900FFFF" + $"FFFFFFFFFFFFFFFFFFFF00003FD93F00F9F9F900F9F900F90000F9F9F900FFFF" + $"FFFFFFFFFFFFFFFFFF00D93FD93FD900F9F9000000F900F900F9F9F9F900FFFF" + $"FFFFFFFFFFFFFFFF00D93FD93FD93F00F9F9F9F9F9F9F9F9F9F9F9F9F900FFFF" + $"FFFFFFFFFFFFFF00D93FD93FD93FD9000000F9F9F9F9F9F9000000000000FFFF" + $"FFFFFFFFFFFF00D93FD93FD93FD93F003FD90000000000000000FFFFFFFFFFFF" + $"FFFFFFFFFF000000D93FD93FD93FD900D93F003FD93FD93FD93F0000FFFFFFFF" + $"FFFFFFFF00D93FD900000000000000003F003FD93FD93FD93FD93FD900FFFFFF" + $"FFFFFF00D93FD93FD9000000D93F0000003FD93FD93FD93FD93FD93FD900FFFF" + $"FFFF00D93FD93FD93F003FD900003F000000000000003FD93FD93FD93FD900FF" + $"FF00D93FD93FD93FD93F0000003F0000003FD93FD93F003FD93FD93FD98300FF" + $"FF003FD93FD93FD93FD93FD93F003FD900003FD900003FD93FD93FD9838300FF" + $"00D9D93FD93FD93FD93FD93F003FD900D9000000003FD93FD93FD983838300FF" + $"00D9D9D93FD93FD93FD93F003FD93F003FD93FD93F0000D93FD98383838300FF" + $"00D9D9D9D9D9D93FD93F003FD93FD900D93FD93FD93FD9000083838383000FFF" + $"FF00D9D9D9D9D9D93F003FD93FD93FD93FD93FD93FD93FD900838383000FFFFF" + $"FFFF0000D9D9D9D9D901D93FD93FD93FD93FD93FD93FD983008383000FFFFFFF" + $"FFFFFFFF0000D9D9D901D9D93FD93FD93FD93FD93FD983830083000FFFFFFFFF" + $"FFFFFFFFFFFF0000D900D9D9D9D9D93FD93FD93FD983838300000FFFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000D9D9D9D9D9D93FD93FD983838383000FFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF0000D9D9D9D9D9D9D983838383010FFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF0000D9D9D9D983838383010FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFF0000D9D9838301000EFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(4, "BEOS:L:application/x-gunzip") #'ICON' array +{ + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFF00000000000000FF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF006F6F6F00000000006F6F6F6F6F6F00FF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF006F6F6F6F6F6F6F6F6F6F6F6F6F6F00FF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF006F6F00006F00006F006F00006F6F00FF" + $"FFFFFFFFFFFFFFFFFFFFFFFF000000006F006F6F6F6F006F006F006F006F00FF" + $"FFFFFFFFFFFFFFFFFFFF00003FD93F006F006F006F006F6F006F00006F6F00FF" + $"FFFFFFFFFFFFFFFFFF00D93FD93FD9006F0000006F00006F006F006F6F6F00FF" + $"FFFFFFFFFFFFFFFF00D93FD93FD93F006F6F6F6F6F6F6F6F6F6F6F6F6F6F00FF" + $"FFFFFFFFFFFFFF00D93FD93FD93FD90000006F6F6F6F6F6F00000000000000FF" + $"FFFFFFFFFFFF00D93FD93FD93FD93F003FD90000000000000000FFFFFFFFFFFF" + $"FFFFFFFFFF000000D93FD93FD93FD900D93F003FD93FD93FD93F0000FFFFFFFF" + $"FFFFFFFF00D93FD900000000000000003F003FD93FD93FD93FD93FD900FFFFFF" + $"FFFFFF00D93FD93FD9000000D93F0000003FD93FD93FD93FD93FD93FD900FFFF" + $"FFFF00D93FD93FD93F003FD900003F000000000000003FD93FD93FD93FD900FF" + $"FF00D93FD93FD93FD93F0000003F0000003FD93FD93F003FD93FD93FD98300FF" + $"FF003FD93FD93FD93FD93FD93F003FD900003FD900003FD93FD93FD9838300FF" + $"00D9D93FD93FD93FD93FD93F003FD900D9000000003FD93FD93FD983838300FF" + $"00D9D9D93FD93FD93FD93F003FD93F003FD93FD93F0000D93FD98383838300FF" + $"00D9D9D9D9D9D93FD93F003FD93FD900D93FD93FD93FD900008383838300FFFF" + $"FF00D9D9D9D9D9D93F003FD93FD93FD93FD93FD93FD93FD90083838300FFFFFF" + $"FFFF0000D9D9D9D9D901D93FD93FD93FD93FD93FD93FD98300838300FFFFFFFF" + $"FFFFFFFF0000D9D9D901D9D93FD93FD93FD93FD93FD98383008300FFFFFFFFFF" + $"FFFFFFFFFFFF0000D900D9D9D9D9D93FD93FD93FD98383830000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000D9D9D9D9D9D93FD93FD98383838300FFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF0000D9D9D9D9D9D9D98383838301FFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF0000D9D9D9D98383838301FFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFF0000D9D983830100FFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(0, "BEOS:M:application/x-gzip") #'MICN' array +{ + $"FFFFFFFFFFFFFF3D033D03023D0302FF" + $"FFFFFFFFFFFFFF3D6F6F6F6F6F6F03FF" + $"FFFFFFFFFF00003D6F6F6F6F6F6F03FF" + $"FFFFFFFF00D9D93D6F6F6F6F6F6F03FF" + $"FFFFFF00D9D9D9023D033D033D0303FF" + $"FFFF000000000000D900D9D9D90000FF" + $"FF00D9D900D9D900000000D9D9D98300" + $"00D9D9D9D9010000D9D9D900D93F8300" + $"003F3FD9D9D90000000000D93F838300" + $"00D9D93F3F00D900D9D9D900008300FF" + $"0000D9D9003F3F00D9D93F830000FFFF" + $"FFFF000000D9D93F3F3F838300FFFFFF" + $"FFFFFFFF0000D9D9D9838301FFFFFFFF" + $"FFFFFFFFFFFF0000D98301FFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(1, "BEOS:M:application/x-tar") #'MICN' array +{ + $"FFFFFFFFFFFFFF03330403F7040204FF" + $"FFFFFFFFFFFFFF035A5A5A5A5A5A03FF" + $"FFFFFFFFFF0000035A5A5A5A5A5A03FF" + $"FFFFFFFF00D9D9035A5A5A5A5A5A03FF" + $"FFFFFF00D9D9D90303F7030303F704FF" + $"FFFF000000000000D900D9D9D90000FF" + $"FF00D9D900D9D900000000D9D9D98300" + $"00D9D9D9D9010000D9D9D900D93F8300" + $"003F3FD9D9D90000000000D93F838300" + $"00D9D93F3F00D900D9D9D900008300FF" + $"0000D9D9003F3F00D9D93F830000FFFF" + $"FFFF000000D9D93F3F3F838300FFFFFF" + $"FFFFFFFF0000D9D9D9838301FFFFFFFF" + $"FFFFFFFFFFFF0000D98301FFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(2, "BEOS:M:application/x-zip-compressed") #'MICN' array +{ + $"FFFFFFFFFFFFFF0000000000000000FF" + $"FFFFFFFFFFFFFF00F9F9F9F9F9F900FF" + $"FFFFFFFFFF000000F9F9F9F9F9F900FF" + $"FFFFFFFF00D9D900F9F9F9F9F9F900FF" + $"FFFFFF00D9D9D90000000000000000FF" + $"FFFF000000000000D900D9D9D90000FF" + $"FF00D9D900D9D900000000D9D9D98300" + $"00D9D9D9D9010000D9D9D900D93F8300" + $"003F3FD9D9D90000000000D93F838300" + $"00D9D93F3F00D900D9D9D900008300FF" + $"0000D9D9003F3F00D9D93F830000FFFF" + $"FFFF000000D9D93F3F3F838300FFFFFF" + $"FFFFFFFF0000D9D9D9838301FFFFFFFF" + $"FFFFFFFFFFFF0000D98301FFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(3, "BEOS:M:application/zip") #'MICN' array +{ + $"FFFFFFFFFFFFFF0000000000000000FF" + $"FFFFFFFFFFFFFF00F9F9F9F9F9F900FF" + $"FFFFFFFFFF000000F9F9F9F9F9F900FF" + $"FFFFFFFF00D9D900F9F9F9F9F9F900FF" + $"FFFFFF00D9D9D90000000000000000FF" + $"FFFF000000000000D900D9D9D90000FF" + $"FF00D9D900D9D900000000D9D9D98300" + $"00D9D9D9D9010000D9D9D900D93F8300" + $"003F3FD9D9D90000000000D93F838300" + $"00D9D93F3F00D900D9D9D900008300FF" + $"0000D9D9003F3F00D9D93F830000FFFF" + $"FFFF000000D9D93F3F3F838300FFFFFF" + $"FFFFFFFF0000D9D9D9838301FFFFFFFF" + $"FFFFFFFFFFFF0000D98301FFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(4, "BEOS:M:application/x-gunzip") #'MICN' array +{ + $"FFFFFFFFFFFFFF3D033D03023D0302FF" + $"FFFFFFFFFFFFFF3D6F6F6F6F6F6F03FF" + $"FFFFFFFFFF00003D6F6F6F6F6F6F03FF" + $"FFFFFFFF00D9D93D6F6F6F6F6F6F03FF" + $"FFFFFF00D9D9D9023D033D033D0303FF" + $"FFFF000000000000D900D9D9D90000FF" + $"FF00D9D900D9D900000000D9D9D98300" + $"00D9D9D9D9010000D9D9D900D93F8300" + $"003F3FD9D9D90000000000D93F838300" + $"00D9D93F3F00D900D9D9D900008300FF" + $"0000D9D9003F3F00D9D93F830000FFFF" + $"FFFF000000D9D93F3F3F838300FFFFFF" + $"FFFFFFFF0000D9D9D9838301FFFFFFFF" + $"FFFFFFFFFFFF0000D98301FFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0000FFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(1, "BEOS:FILE_TYPES") message +{ + "types" = "application/x-gzip", + "types" = "application/x-tar", + "types" = "application/x-zip-compressed", + "types" = "application/zip", + "types" = "application/x-gunzip" +}; diff --git a/src/apps/expander/ExpanderApp.cpp b/src/apps/expander/ExpanderApp.cpp new file mode 100644 index 0000000000..3a8efa2f80 --- /dev/null +++ b/src/apps/expander/ExpanderApp.cpp @@ -0,0 +1,115 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderApp.cpp +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#include +#include "ExpanderApp.h" +#include "ExpanderWindow.h" + +const char *APP_SIG = "application/x-vnd.obos-Expander"; + +int main(int, char **) +{ + ExpanderApp theApp; + theApp.Run(); + return 0; +} + +ExpanderApp::ExpanderApp() + : BApplication(APP_SIG) +{ + BPoint windowPosition = fSettings.Message().FindPoint("window_position"); + BRect windowFrame(0,0,450,120); + windowFrame.OffsetBy(windowPosition); + BMessage settings(fSettings.Message()); + fWindow = new ExpanderWindow(windowFrame, NULL, &settings); +} + +void +ExpanderApp::AboutRequested() +{ + BAlert *alert = new BAlert("about", "Expand-O-Matic\n" + "\twritten by Jérôme Duval\n" + "\tCopyright 2004, OpenBeOS.\n\n" + "original Be version by \n" + "Dominic, Hiroshi, Peter, Pavel and Robert\n", "Ok"); + BTextView *view = alert->TextView(); + BFont font; + + view->SetStylable(true); + + view->GetFont(&font); + font.SetSize(18); + font.SetFace(B_BOLD_FACE); + view->SetFontAndColor(0, 14, &font); + + alert->Go(); + +} + + +void +ExpanderApp::ReadyToRun() +{ + +} + + +void +ExpanderApp::ArgvReceived(int32 argc, char **argv) +{ + BMessage *msg = NULL; + for (int32 i = 1; i < argc; i++) { + entry_ref ref; + status_t err = get_ref_for_path(argv[i], &ref); + if (err == B_OK) { + if (!msg) { + msg = new BMessage; + msg->what = B_REFS_RECEIVED; + } + msg->AddRef("refs", &ref); + } + } + if (msg) + RefsReceived(msg); +} + + +void +ExpanderApp::RefsReceived(BMessage *msg) +{ + BMessenger messenger(fWindow); + msg->AddBool("fromApp", true); + messenger.SendMessage(msg); +} + + +void +ExpanderApp::UpdateSettingsFrom(BMessage *message) +{ + fSettings.UpdateFrom(message); +} diff --git a/src/apps/expander/ExpanderApp.h b/src/apps/expander/ExpanderApp.h new file mode 100644 index 0000000000..4096e45df7 --- /dev/null +++ b/src/apps/expander/ExpanderApp.h @@ -0,0 +1,52 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderApp.h +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#ifndef _ExpanderApp_h +#define _ExpanderApp_h + +#include +#include "ExpanderSettings.h" +#include "ExpanderWindow.h" + +class ExpanderApp : public BApplication { +public: + ExpanderApp(); + +public: + virtual void AboutRequested(); + virtual void ArgvReceived(int32 argc, char **argv); + virtual void ReadyToRun(); + virtual void RefsReceived(BMessage *msg); + + ExpanderSettings fSettings; + void UpdateSettingsFrom(BMessage *message); +private: + ExpanderWindow *fWindow; +}; + +#endif /* _ExpanderApp_h */ diff --git a/src/apps/expander/ExpanderPreferences.cpp b/src/apps/expander/ExpanderPreferences.cpp new file mode 100644 index 0000000000..758c2f0c47 --- /dev/null +++ b/src/apps/expander/ExpanderPreferences.cpp @@ -0,0 +1,267 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderPreferences.cpp +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#include "ExpanderPreferences.h" +#include +#include +#include +#include + +const uint32 MSG_OK = 'mgOK'; +const uint32 MSG_CANCEL = 'mCan'; +const uint32 MSG_LEAVEDEST = 'mLed'; +const uint32 MSG_SAMEDIR = 'mSad'; +const uint32 MSG_DESTUSE = 'mDeu'; +const uint32 MSG_DESTTEXT = 'mDet'; +const uint32 MSG_DESTSELECT = 'mDes'; + +ExpanderPreferences::ExpanderPreferences(BMessage *settings) + : BWindow(BRect(0, 0, 325, 305), "Expand-O-Matic", B_MODAL_WINDOW, + B_NOT_CLOSABLE | B_NOT_RESIZABLE), + fSettings(settings), + fUsePanel(NULL) +{ + + BRect rect = Bounds(); + BBox *background = new BBox(rect, "background", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); + AddChild(background); + + rect.OffsetBy(11,9); + rect.bottom -= 64; + rect.right -= 22; + BBox *box = new BBox(rect, "background", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); + box->SetLabel("Expander Preferences"); + background->AddChild(box); + + + BRect frameRect = box->Bounds(); + frameRect.OffsetBy(15,23); + frameRect.right = frameRect.left + 100; + frameRect.bottom = frameRect.top + 20; + BRect textRect(frameRect); + textRect.OffsetTo(B_ORIGIN); + textRect.InsetBy(1,1); + BTextView *textView = new BTextView(frameRect, "expansion", textRect, + be_plain_font, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); + textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + box->AddChild(textView); + textView->SetText("Expansion:"); + + frameRect.OffsetBy(0, 58); + textRect.OffsetBy(0, 58); + textView = new BTextView(frameRect, "destinationFolder", textRect, + be_plain_font, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); + textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + box->AddChild(textView); + textView->SetText("Destination Folder:"); + + frameRect.OffsetBy(0, 84); + textRect.OffsetBy(0, 84); + textView = new BTextView(frameRect, "other", textRect, + be_plain_font, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); + textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + box->AddChild(textView); + textView->SetText("Other:"); + + rect = box->Bounds(); + rect.OffsetBy(25, 42); + rect.bottom = rect.top + 20; + rect.right = rect.left + 220; + fAutoExpand = new BCheckBox(rect, "autoExpand", "Automatically expand files", NULL); + box->AddChild(fAutoExpand); + + rect.OffsetBy(0, 17); + fCloseWindow = new BCheckBox(rect, "closeWindowWhenDone", "Close window when done expanding", NULL); + box->AddChild(fCloseWindow); + + rect.OffsetBy(0, 50); + fLeaveDest = new BRadioButton(rect, "leaveDest", "Leave destination folder path empty", + new BMessage(MSG_LEAVEDEST)); + box->AddChild(fLeaveDest); + + rect.OffsetBy(0, 17); + fSameDest = new BRadioButton(rect, "sameDir", "Same directory as source (archive) file", + new BMessage(MSG_SAMEDIR)); + box->AddChild(fSameDest); + + rect.OffsetBy(0, 17); + BRect useRect = rect; + useRect.right = useRect.left + 50; + fDestUse = new BRadioButton(useRect, "destUse", "Use:", + new BMessage(MSG_DESTUSE)); + box->AddChild(fDestUse); + + textRect = rect; + textRect.OffsetBy(45, 0); + textRect.right = textRect.left + 158; + fDestText = new BTextControl(textRect, "destText", "", "", new BMessage(MSG_DESTTEXT)); + fDestText->SetDivider(0); + fDestText->TextView()->MakeEditable(false); + box->AddChild(fDestText); + fDestText->SetEnabled(false); + + textRect.OffsetBy(168, -4); + textRect.right = textRect.left + 50; + fSelect = new BButton(textRect, "selectButton", "Select", new BMessage(MSG_DESTSELECT)); + box->AddChild(fSelect); + fSelect->SetEnabled(false); + + rect.OffsetBy(0, 50); + fOpenDest = new BCheckBox(rect, "openDestination", "Open destination folder after extraction", NULL); + box->AddChild(fOpenDest); + + rect.OffsetBy(0, 17); + fAutoShow = new BCheckBox(rect, "autoShow", "Automatically show contents listing", NULL); + box->AddChild(fAutoShow); + + rect = BRect(Bounds().right-89, Bounds().bottom-40, + Bounds().right-14, Bounds().bottom-16); + BButton *button = new BButton(rect, "OKButton", "OK", + new BMessage(MSG_OK)); + background->AddChild(button); + button->MakeDefault(true); + + rect.OffsetBy(-89, 0); + button = new BButton(rect, "CancelButton", "Cancel", + new BMessage(MSG_CANCEL)); + background->AddChild(button); + + BScreen screen; + MoveBy((screen.Frame().Width()-Bounds().Width())/2, + (screen.Frame().Height()-Bounds().Height())/2); + + bool automatically_expand_files; + bool close_when_done; + int8 destination_folder; + entry_ref ref; + bool open_destination_folder; + bool show_contents_listing; + if ((settings->FindBool("automatically_expand_files", &automatically_expand_files) == B_OK) + && automatically_expand_files) + fAutoExpand->SetValue(B_CONTROL_ON); + + if ((settings->FindBool("close_when_done", &close_when_done) == B_OK) + && close_when_done) + fCloseWindow->SetValue(B_CONTROL_ON); + + if (settings->FindInt8("destination_folder", &destination_folder) == B_OK) { + switch (destination_folder) { + case 0x63: + fSameDest->SetValue(B_CONTROL_ON); + break; + case 0x65: + fDestUse->SetValue(B_CONTROL_ON); + fDestText->SetEnabled(true); + fSelect->SetEnabled(true); + break; + case 0x66: + fLeaveDest->SetValue(B_CONTROL_ON); + break; + } + } + + if (settings->FindRef("destination_folder_use", &fRef) == B_OK) { + BEntry entry(&fRef); + if (entry.Exists()) { + BPath path(&entry); + fDestText->SetText(path.Path()); + } + } + + if ((settings->FindBool("open_destination_folder", &open_destination_folder) == B_OK) + && open_destination_folder) + fOpenDest->SetValue(B_CONTROL_ON); + + if ((settings->FindBool("show_contents_listing", &show_contents_listing) == B_OK) + && show_contents_listing) + fAutoShow->SetValue(B_CONTROL_ON); +} + + +ExpanderPreferences::~ExpanderPreferences() +{ +} + + +void +ExpanderPreferences::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case MSG_DESTSELECT: + if (!fUsePanel) + fUsePanel = new DirectoryFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL, + B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter(), true); + fUsePanel->Show(); + break; + case MSG_DIRECTORY: + { + entry_ref ref; + fUsePanel->GetPanelDirectory(&ref); + fRef = ref; + BEntry entry(&ref); + BPath path(&entry); + fDestText->SetText(path.Path()); + fUsePanel->Hide(); + } + break; + case B_REFS_RECEIVED: + if (msg->FindRef("refs", 0, &fRef) == B_OK) { + BEntry entry(&fRef, true); + BPath path(&entry); + fDestText->SetText(path.Path()); + } + break; + case MSG_LEAVEDEST: + case MSG_SAMEDIR: + fDestText->SetEnabled(false); + fSelect->SetEnabled(false); + break; + case MSG_DESTUSE: + fDestText->SetEnabled(true); + fSelect->SetEnabled(true); + fDestText->TextView()->MakeEditable(false); + break; + case MSG_CANCEL: + Hide(); + break; + case MSG_OK: + fSettings->ReplaceBool("automatically_expand_files", fAutoExpand->Value() == B_CONTROL_ON); + fSettings->ReplaceBool("close_when_done", fCloseWindow->Value() == B_CONTROL_ON); + fSettings->ReplaceInt8("destination_folder", (fSameDest->Value() == B_CONTROL_ON) ? 0x63 + : ( (fLeaveDest->Value() == B_CONTROL_ON) ? 0x66 : 0x65) ); + fSettings->ReplaceRef("destination_folder_use", &fRef); + fSettings->ReplaceBool("open_destination_folder", fOpenDest->Value() == B_CONTROL_ON); + fSettings->ReplaceBool("show_contents_listing", fAutoShow->Value() == B_CONTROL_ON); + Hide(); + break; + default: + break; + } +} diff --git a/src/apps/expander/ExpanderPreferences.h b/src/apps/expander/ExpanderPreferences.h new file mode 100644 index 0000000000..4800ff8091 --- /dev/null +++ b/src/apps/expander/ExpanderPreferences.h @@ -0,0 +1,57 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderPreferences.h +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#ifndef _ExpanderPreferences_h +#define _ExpanderPreferences_h + +#include "DirectoryFilePanel.h" +#include +#include +#include +#include +#include +#include +#include + +class ExpanderPreferences : public BWindow { +public: + ExpanderPreferences(BMessage *settings); + virtual ~ExpanderPreferences(); + virtual void MessageReceived(BMessage *msg); + +private: + BMessage *fSettings; + BCheckBox *fAutoExpand, *fCloseWindow, *fAutoShow, *fOpenDest; + BRadioButton *fDestUse, *fSameDest, *fLeaveDest; + BButton *fSelect; + BTextControl *fDestText; + entry_ref fRef; + DirectoryFilePanel *fUsePanel; +}; + +#endif /* _ExpanderPreferences_h */ diff --git a/src/apps/expander/ExpanderRules.cpp b/src/apps/expander/ExpanderRules.cpp new file mode 100644 index 0000000000..e0f633694d --- /dev/null +++ b/src/apps/expander/ExpanderRules.cpp @@ -0,0 +1,180 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderRules.cpp +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ +#include "ExpanderRules.h" + +#include +#include +#include +#include +#include +#include + +ExpanderRule::ExpanderRule(BString mimetype, BString filenameExtension, + BString listingCmd, BString expandCmd) + : fMimeType(mimetype.String()), + fFilenameExtension(filenameExtension), + fListingCmd(listingCmd), + fExpandCmd(expandCmd) +{ + +} + + +ExpanderRule::ExpanderRule(const char* mimetype, const char* filenameExtension, + const char* listingCmd, const char* expandCmd) + : fMimeType(mimetype), + fFilenameExtension(filenameExtension), + fListingCmd(listingCmd), + fExpandCmd(expandCmd) +{ + +} + + +ExpanderRules::ExpanderRules() +{ + fList.AddItem(new ExpanderRule("", ".tar.gz", "zcat %s | tar -tvf -", "zcat %s | tar -xvf -")); + fList.AddItem(new ExpanderRule("", ".tar.Z", "zcat %s | tar -tvf -", "zcat %s | tar -xvf -")); + fList.AddItem(new ExpanderRule("", ".tgz", "zcat %s | tar -tvf -", "zcat %s | tar -xvf -")); + fList.AddItem(new ExpanderRule("application/x-tar", ".tar", "tar -tvf %s", "tar -xf %s")); + fList.AddItem(new ExpanderRule("application/x-gzip", ".gz", "echo %s | sed 's/.gz$//g'", "gunzip %s")); + fList.AddItem(new ExpanderRule("application/zip", ".zip", "unzip -l %s", "unzip -o %s")); + fList.AddItem(new ExpanderRule("application/x-zip-compressed", ".zip", "unzip -l %s", "unzip -o %s")); + + BFile file; + if (Open(&file) != B_OK) + return; + + int fd = file.Dup(); + FILE * f = fdopen(fd, "r"); + + char buffer[1024]; + BString strings[4]; + while (fgets(buffer, 1024-1, f)!=NULL) { + int32 i=0, j=0; + int32 firstQuote = -1; + while (buffer[i]!= '#' && buffer[i]!= '\n' && j<4) { + if (((j==0)||(j>1))&&(buffer[i] == '"')) { + if (firstQuote >= 0) { + strings[j++].SetTo(&buffer[firstQuote+1], i-firstQuote-1); + firstQuote = -1; + } else + firstQuote = i; + } else if ((j==1)&&((buffer[i]==' ')||(buffer[i]=='\t'))){ + if (firstQuote >= 0) { + if (firstQuote+1!=i) { + strings[j++].SetTo(&buffer[firstQuote+1], i-firstQuote-1); + firstQuote = -1; + } else + firstQuote = i; + } else + firstQuote = i; + } + i++; + } + if (j==4) { + fList.AddItem(new ExpanderRule(strings[0], strings[1], strings[2], strings[3])); + } + } + fclose(f); + close(fd); +} + + +ExpanderRules::~ExpanderRules() +{ + void *item; + while ((item = fList.RemoveItem((int32)0))) + delete item; +} + + +status_t +ExpanderRules::Open(BFile *file) +{ + BPath path; + if (find_directory(B_USER_CONFIG_DIRECTORY, &path) != B_OK) + return B_ERROR; + + path.Append("etc/expander.rules"); + if (file->SetTo(path.Path(), B_READ_ONLY) == B_OK) + return B_OK; + + if (find_directory(B_COMMON_ETC_DIRECTORY, &path) != B_OK) + return B_ERROR; + + path.Append("expander.rules"); + + return file->SetTo(path.Path(), B_READ_ONLY); +} + + +ExpanderRule * +ExpanderRules::MatchingRule(BString &fileName, const char *filetype) +{ + int32 count = fList.CountItems(); + int32 length = fileName.Length(); + for (int32 i=0; iMimeType().IsValid()) || (rule->MimeType()==filetype)) + && (fileName.FindLast(rule->FilenameExtension())==(length-rule->FilenameExtension().Length()))) + return rule; + } + return NULL; +} + + +ExpanderRule * +ExpanderRules::MatchingRule(const entry_ref *ref) +{ + BNode node(ref); + BNodeInfo nodeInfo(&node); + char type[B_MIME_TYPE_LENGTH]; + nodeInfo.GetType(type); + BString fileName(ref->name); + return MatchingRule(fileName, type); +} + + +RuleRefFilter::RuleRefFilter(ExpanderRules &rules) + : BRefFilter(), + fRules(rules) +{ +} + + +bool +RuleRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat *st, + const char *filetype) +{ + if (node->IsDirectory() || node->IsSymLink()) + return true; + + BString fileName(ref->name); + return (fRules.MatchingRule(fileName, filetype)!=NULL); +} diff --git a/src/apps/expander/ExpanderRules.h b/src/apps/expander/ExpanderRules.h new file mode 100644 index 0000000000..c8aa77d10a --- /dev/null +++ b/src/apps/expander/ExpanderRules.h @@ -0,0 +1,78 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderRules.h +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#ifndef _ExpanderRules_h +#define _ExpanderRules_h + +#include +#include +#include +#include +#include + +class ExpanderRule { + public: + ExpanderRule(BString mimetype, BString filenameExtension, + BString listingCmd, BString expandCmd); + ExpanderRule(const char* mimetype, const char* filenameExtension, + const char* listingCmd, const char* expandCmd); + BMimeType &MimeType() { return fMimeType;} + BString &FilenameExtension() { return fFilenameExtension;} + BString &ListingCmd() { return fListingCmd;} + BString &ExpandCmd() { return fExpandCmd;} + private: + BMimeType fMimeType; + BString fFilenameExtension; + BString fListingCmd; + BString fExpandCmd; +}; + + +class ExpanderRules { + public: + ExpanderRules(); + ~ExpanderRules(); + ExpanderRule *MatchingRule(BString &fileName, const char *filetype); + ExpanderRule *MatchingRule(const entry_ref *ref); + private: + status_t Open(BFile *file); + + BList fList; +}; + + +class RuleRefFilter : public BRefFilter { + public: + RuleRefFilter(ExpanderRules &rules); + bool Filter(const entry_ref *ref, BNode* node, struct stat *st, + const char *filetype); + protected: + ExpanderRules &fRules; +}; + +#endif /* _ExpanderRules_h */ \ No newline at end of file diff --git a/src/apps/expander/ExpanderSettings.cpp b/src/apps/expander/ExpanderSettings.cpp new file mode 100644 index 0000000000..d56447cd7f --- /dev/null +++ b/src/apps/expander/ExpanderSettings.cpp @@ -0,0 +1,212 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderSettings.cpp +// +// Code from Diskprobe by Axel Dörfler +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ +#include "ExpanderSettings.h" + +#include +#include +#include +#include +#include +#include + +// Format of Expander_Settings +// 1st byte : unknown (0x1) +// 2nd byte : Automatically expand files (default : 0x0) +// 3rd byte : Close when done (default : 0x0) +// 4th byte : 0x66 +// 0x63 (default) +// 0x65 +// 5th byte : unknown (0x0) +// 4 bytes : dev_t (default : 0xffff) +// 8 bytes : ino_t (default : 0xfffffffff) +// 4 bytes : name length (big endian) (default : 0x0) +// n bytes : name (default : "") +// 1 byte : Open destination folder (default : 0x1) +// 1 byte : Show content listing (default : 0x0) +// 4 bytes : window position topleft x (default : 0x4842) +// 4 bytes : window position topleft y (default : 0x4842) + +ExpanderSettings::ExpanderSettings() + : + fMessage(kMsgExpanderSettings), + fUpdated(false) +{ + fMessage.AddBool("automatically_expand_files", false); + fMessage.AddBool("close_when_done", false); + fMessage.AddInt8("destination_folder", 0x63); + entry_ref ref; + fMessage.AddRef("destination_folder_use", &ref); + fMessage.AddBool("open_destination_folder", true); + fMessage.AddBool("show_contents_listing", false); + fMessage.AddPoint("window_position", BPoint(50, 50)); + + BFile file; + if (Open(&file, B_READ_ONLY) != B_OK) + return; + + // ToDo: load/save settings as flattened BMessage - but not yet, + // since that will break compatibility with R5's Expander + + bool unknown; + bool automatically_expand_files; + bool close_when_done; + int8 destination_folder; + bool open_destination_folder; + bool show_contents_listing; + BPoint position; + int32 name_size; + if ( + (file.Read(&unknown, sizeof(unknown)) == sizeof(unknown)) + && (file.Read(&automatically_expand_files, sizeof(automatically_expand_files)) == sizeof(automatically_expand_files)) + && (file.Read(&close_when_done, sizeof(close_when_done)) == sizeof(close_when_done)) + && (file.Read(&destination_folder, sizeof(destination_folder)) == sizeof(destination_folder)) + && (file.Read(&unknown, sizeof(unknown)) == sizeof(unknown)) + && (file.Read(&ref.device, sizeof(ref.device)) == sizeof(ref.device)) + && (file.Read(&ref.directory, sizeof(ref.directory)) == sizeof(ref.directory)) + && (file.Read(&name_size, sizeof(name_size)) == sizeof(name_size)) + && ((name_size <= 0) || (ref.name = (char*)malloc(name_size))) + && (file.Read(ref.name, name_size) == name_size) + && (file.Read(&open_destination_folder, sizeof(open_destination_folder)) == sizeof(open_destination_folder)) + && (file.Read(&show_contents_listing, sizeof(show_contents_listing)) == sizeof(show_contents_listing)) + && (file.Read(&position, sizeof(position)) == sizeof(position)) + ) { + + // check if the window position is on screen at all + BScreen screen; + if (screen.Frame().Contains(position)) + fMessage.ReplacePoint("window_position", position); + + fMessage.ReplaceBool("automatically_expand_files", automatically_expand_files); + fMessage.ReplaceBool("close_when_done", close_when_done); + if(destination_folder == 0x66 || destination_folder == 0x63 || destination_folder == 0x65) + fMessage.ReplaceInt8("destination_folder", destination_folder); + BEntry entry(&ref); + if(entry.Exists()) + fMessage.ReplaceRef("destination_folder_use", &ref); + fMessage.ReplaceBool("open_destination_folder", open_destination_folder); + fMessage.ReplaceBool("show_contents_listing", show_contents_listing); + } +} + + +ExpanderSettings::~ExpanderSettings() +{ + // only save the settings if something has changed + if (!fUpdated) + return; + + BFile file; + if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK) + return; + + bool automatically_expand_files; + bool close_when_done; + int8 destination_folder; + entry_ref ref; + bool open_destination_folder; + bool show_contents_listing; + BPoint position; + bool unknown = 1; + + if ((fMessage.FindPoint("window_position", &position) == B_OK) + && (fMessage.FindBool("automatically_expand_files", &automatically_expand_files) == B_OK) + && (fMessage.FindBool("close_when_done", &close_when_done) == B_OK) + && (fMessage.FindInt8("destination_folder", &destination_folder) == B_OK) + && (fMessage.FindRef("destination_folder_use", &ref) == B_OK) + && (fMessage.FindBool("open_destination_folder", &open_destination_folder) == B_OK) + && (fMessage.FindBool("show_contents_listing", &show_contents_listing) == B_OK) ) { + + file.Write(&unknown, sizeof(unknown)); + file.Write(&automatically_expand_files, sizeof(automatically_expand_files)); + file.Write(&close_when_done, sizeof(close_when_done)); + file.Write(&destination_folder, sizeof(destination_folder)); + unknown = 0; + file.Write(&unknown, sizeof(unknown)); + file.Write(&ref.device, sizeof(ref.device)); + file.Write(&ref.directory, sizeof(ref.directory)); + int32 name_size = 0; + if(ref.name) + name_size = strlen(ref.name); + file.Write(&name_size, sizeof(name_size)); + file.Write(ref.name, name_size); + file.Write(&open_destination_folder, sizeof(open_destination_folder)); + file.Write(&show_contents_listing, sizeof(show_contents_listing)); + file.Write(&position, sizeof(position)); + } + +} + + +status_t +ExpanderSettings::Open(BFile *file, int32 mode) +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return B_ERROR; + + path.Append("Expander_Settings"); + + return file->SetTo(path.Path(), mode); +} + + +void +ExpanderSettings::UpdateFrom(BMessage *message) +{ + bool automatically_expand_files; + bool close_when_done; + int8 destination_folder; + entry_ref ref; + bool open_destination_folder; + bool show_contents_listing; + BPoint position; + + if (message->FindPoint("window_position", &position) == B_OK) + fMessage.ReplacePoint("window_position", position); + + if (message->FindBool("automatically_expand_files", &automatically_expand_files) == B_OK) + fMessage.ReplaceBool("automatically_expand_files", automatically_expand_files); + + if (message->FindBool("close_when_done", &close_when_done) == B_OK) + fMessage.ReplaceBool("close_when_done", close_when_done); + + if (message->FindInt8("destination_folder", &destination_folder) == B_OK) + fMessage.ReplaceInt8("destination_folder", destination_folder); + + if (message->FindRef("destination_folder_use", &ref) == B_OK) + fMessage.ReplaceRef("destination_folder_use", &ref); + + if (message->FindBool("open_destination_folder", &open_destination_folder) == B_OK) + fMessage.ReplaceBool("open_destination_folder", open_destination_folder); + + if (message->FindBool("show_contents_listing", &show_contents_listing) == B_OK) + fMessage.ReplaceBool("show_contents_listing", show_contents_listing); + + fUpdated = true; +} diff --git a/src/apps/expander/ExpanderSettings.h b/src/apps/expander/ExpanderSettings.h new file mode 100644 index 0000000000..126946815c --- /dev/null +++ b/src/apps/expander/ExpanderSettings.h @@ -0,0 +1,52 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderSettings.h +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#ifndef _ExpanderSettings_h +#define _ExpanderSettings_h + +#include +#include + +static const uint32 kMsgExpanderSettings = 'Exst'; + +class ExpanderSettings { + public: + ExpanderSettings(); + ~ExpanderSettings(); + + const BMessage &Message() const { return fMessage; } + void UpdateFrom(BMessage *message); + + private: + status_t Open(BFile *file, int32 mode); + + BMessage fMessage; + bool fUpdated; +}; + +#endif /* _ExpanderSettings_h */ \ No newline at end of file diff --git a/src/apps/expander/ExpanderThread.cpp b/src/apps/expander/ExpanderThread.cpp new file mode 100644 index 0000000000..ab0462f5d7 --- /dev/null +++ b/src/apps/expander/ExpanderThread.cpp @@ -0,0 +1,276 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderThread.cpp +// +// Copyright (c) 2004 OpenBeOS Project +// +// Original code from ZipOMatic by jonas.sundstrom@kirilla.com +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ +#include +#include +#include +#include +#include +#include + +const char * ExpanderThreadName = "ExpanderThread"; + +ExpanderThread::ExpanderThread (BMessage * refs_message, BMessenger * messenger) +: GenericThread(ExpanderThreadName, B_NORMAL_PRIORITY, refs_message), + fWindowMessenger(messenger), + fThreadId(-1), + fStdIn(-1), + fStdOut(-1), + fStdErr(-1), + fExpanderOutput(NULL), + fExpanderOutputString(), + fExpanderOutputBuffer(new char [4096]) +{ + SetDataStore(new BMessage (* refs_message)); // leak? + // prevents bug with B_SIMPLE_DATA + // (drag&drop messages) +} + +ExpanderThread::~ExpanderThread() +{ + delete fWindowMessenger; + delete [] fExpanderOutputBuffer; +} + +status_t +ExpanderThread::ThreadStartup() +{ + status_t status = B_OK; + entry_ref srcRef, destRef; + BString cmd; + + if ((status = GetDataStore()->FindRef("srcRef", &srcRef))!=B_OK) + return status; + if ((status = GetDataStore()->FindRef("destRef", &destRef))!=B_OK) + return status; + if ((status = GetDataStore()->FindString("cmd", &cmd))!=B_OK) + return status; + + BPath path(&srcRef); + BString pathString(path.Path()); + pathString.CharacterEscape("\"$`", '\\'); + pathString.Prepend("\""); + pathString.Append("\""); + cmd.ReplaceAll("%s", pathString.String()); + + path.SetTo(&destRef); + chdir(path.Path()); + + int32 argc = 3; + const char ** argv = new const char * [argc + 1]; + + argv[0] = strdup("/bin/sh"); + argv[1] = strdup("-c"); + argv[2] = strdup(cmd.String()); + argv[argc] = NULL; + + fThreadId = PipeCommand(argc, argv, fStdIn, fStdOut, fStdErr); + + delete [] argv; + + if (fThreadId < 0) + return fThreadId; + + resume_thread(fThreadId); + + fExpanderOutput = fdopen(fStdOut, "r"); + + return B_OK; +} + +status_t +ExpanderThread::ExecuteUnit (void) +{ + // read output from command + // send it to window + + char * output_string; + output_string = fgets(fExpanderOutputBuffer , 4096-1, fExpanderOutput); + + if (output_string == NULL) + return EOF; + + BMessage message('outp'); + message.AddString("output", output_string); + for (int32 i=0; i<5; i++) { + output_string = fgets(fExpanderOutputBuffer , 4096-1, fExpanderOutput); + if(!output_string) + break; + message.AddString("output", output_string); + } + fWindowMessenger->SendMessage(&message); + + return B_OK; +} + +status_t +ExpanderThread::ThreadShutdown(void) +{ + close(fStdIn); + close(fStdOut); + close(fStdErr); + + return B_OK; +} + +void +ExpanderThread::ThreadStartupFailed(status_t status) +{ + fprintf(stderr, "ExpanderThread::ThreadStartupFailed() : %s\n", strerror(status)); + + Quit(); +} + +void +ExpanderThread::ExecuteUnitFailed(status_t status) +{ + if (status == EOF) { + // thread has finished, been quit or killed, we don't know + fWindowMessenger->SendMessage(new BMessage('exit')); + } else { + // explicit error - communicate error to Window + fWindowMessenger->SendMessage(new BMessage('exrr')); + } + + Quit(); +} + +void +ExpanderThread::ThreadShutdownFailed(status_t status) +{ + fprintf(stderr, "ExpanderThread::ThreadShutdownFailed() %s\n", strerror(status)); +} + + +status_t +ExpanderThread::ProcessRefs(BMessage *msg) +{ + return B_OK; +} + +thread_id +ExpanderThread::PipeCommand(int argc, const char **argv, int &in, int &out, int &err, const char **envp) +{ + // This function written by Peter Folk + // and published in the BeDevTalk FAQ + // http://www.abisoft.com/faq/BeDevTalk_FAQ.html#FAQ-209 + + // Save current FDs + int old_in = dup(0); + int old_out = dup(1); + int old_err = dup(2); + + int filedes[2]; + + /* Create new pipe FDs as stdin, stdout, stderr */ + pipe(filedes); dup2(filedes[0],0); close(filedes[0]); + in=filedes[1]; // Write to in, appears on cmd's stdin + pipe(filedes); dup2(filedes[1],1); close(filedes[1]); + out=filedes[0]; // Read from out, taken from cmd's stdout + pipe(filedes); dup2(filedes[1],2); close(filedes[1]); + err=filedes[0]; // Read from err, taken from cmd's stderr + + // "load" command. + thread_id ret = load_image(argc, argv, envp); + + if (ret < B_OK) + return ret; + + // thread ret is now suspended. + + setpgid(ret, ret); + + // Restore old FDs + close(0); dup(old_in); close(old_in); + close(1); dup(old_out); close(old_out); + close(2); dup(old_err); close(old_err); + + /* Theoretically I should do loads of error checking, but + the calls aren't very likely to fail, and that would + muddy up the example quite a bit. YMMV. */ + + return ret; +} + + +status_t +ExpanderThread::SuspendExternalExpander() +{ + status_t status; + thread_info thread_info; + status = get_thread_info(fThreadId, &thread_info); + BString thread_name = thread_info.name; + + if (status == B_OK) + return send_signal(-fThreadId, SIGSTOP); + else + return status; +} + +status_t +ExpanderThread::ResumeExternalExpander() +{ + status_t status = B_OK; + thread_info thread_info; + status = get_thread_info(fThreadId, &thread_info); + BString thread_name = thread_info.name; + + if (status == B_OK) + return send_signal(-fThreadId, SIGCONT); + else + return status; +} + +status_t +ExpanderThread::InterruptExternalExpander() +{ + status_t status = B_OK; + thread_info thread_info; + status = get_thread_info (fThreadId, &thread_info); + BString thread_name = thread_info.name; + + if (status == B_OK) { + status = send_signal(-fThreadId, SIGINT); + WaitOnExternalExpander(); + } + return status; +} + +status_t +ExpanderThread::WaitOnExternalExpander() +{ + status_t status; + thread_info thread_info; + status = get_thread_info(fThreadId, &thread_info); + BString thread_name = thread_info.name; + + if (status == B_OK) + return wait_for_thread(fThreadId, &status); + else + return status; +} diff --git a/src/apps/expander/ExpanderThread.h b/src/apps/expander/ExpanderThread.h new file mode 100644 index 0000000000..1f7531c62e --- /dev/null +++ b/src/apps/expander/ExpanderThread.h @@ -0,0 +1,81 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderThread.h +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#ifndef __EXPANDERTHREAD_H__ +#define __EXPANDERTHREAD_H__ + +#include +#include +#include +#include +#include + +#include +#include +#include + +extern const char * ExpanderThreadName; + +class ExpanderThread : public GenericThread +{ +public: + ExpanderThread(BMessage *refs_message, BMessenger *messenger); + ~ExpanderThread(); + + status_t SuspendExternalExpander(); + status_t ResumeExternalExpander(); + status_t InterruptExternalExpander(); + status_t WaitOnExternalExpander(); + +private: + + virtual status_t ThreadStartup(); + virtual status_t ExecuteUnit(); + virtual status_t ThreadShutdown(); + + virtual void ThreadStartupFailed(status_t a_status); + virtual void ExecuteUnitFailed(status_t a_status); + virtual void ThreadShutdownFailed(status_t a_status); + + status_t ProcessRefs(BMessage * msg); + + thread_id PipeCommand(int argc, const char **argv, + int & in, int & out, int & err, + const char **envp = (const char **) environ); + + BMessenger * fWindowMessenger; + + thread_id fThreadId; + int fStdIn; + int fStdOut; + int fStdErr; + FILE * fExpanderOutput; + BString fExpanderOutputString; + char * fExpanderOutputBuffer; +}; + +#endif // __EXPANDERTHREAD_H__ diff --git a/src/apps/expander/ExpanderWindow.cpp b/src/apps/expander/ExpanderWindow.cpp new file mode 100644 index 0000000000..af7cfb565b --- /dev/null +++ b/src/apps/expander/ExpanderWindow.cpp @@ -0,0 +1,623 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderWindow.cpp +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ExpanderApp.h" +#include "ExpanderWindow.h" +#include "ExpanderThread.h" +#include "ExpanderPreferences.h" + +const uint32 MSG_SOURCE = 'mSOU'; +const uint32 MSG_DEST = 'mDES'; +const uint32 MSG_EXPAND = 'mEXP'; +const uint32 MSG_SHOW = 'mSHO'; +const uint32 MSG_STOP = 'mSTO'; +const uint32 MSG_CLOSE = 'mCLO'; +const uint32 MSG_PREFERENCES = 'mPRE'; +const uint32 MSG_SOURCETEXT = 'mSTX'; +const uint32 MSG_DESTTEXT = 'mDTX'; +const uint32 MSG_SHOWCONTENTS = 'mSCT'; + +ExpanderWindow::ExpanderWindow(BRect frame_rect, const entry_ref *ref, BMessage *settings) + : BWindow(frame_rect, "Expand-O-Matic", B_TITLED_WINDOW, B_NOT_ZOOMABLE), + fSourceChanged(true), + fListingThread(NULL), + fListingStarted(false), + fExpandingThread(NULL), + fExpandingStarted(false), + fSettings(*settings), + fPreferences(NULL) +{ + fSourcePanel = NULL; + fDestPanel = NULL; + + // create menu bar + fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar"); + BMenu *menu = new BMenu("File"); + BMenuItem *item; + menu->AddItem(item = new BMenuItem("About Expander", new BMessage(B_ABOUT_REQUESTED))); + item->SetTarget(be_app_messenger); + menu->AddSeparatorItem(); + menu->AddItem(fSourceItem = new BMenuItem("Set Source...", new BMessage(MSG_SOURCE), 'O')); + menu->AddItem(fDestItem = new BMenuItem("Set Destination...", new BMessage(MSG_DEST), 'D')); + menu->AddSeparatorItem(); + menu->AddItem(fExpandItem = new BMenuItem("Expand", new BMessage(MSG_EXPAND), 'E')); + fExpandItem->SetEnabled(false); + menu->AddItem(fShowItem = new BMenuItem("Show Contents", new BMessage(MSG_SHOW), 'L')); + fShowItem->SetEnabled(false); + menu->AddSeparatorItem(); + menu->AddItem(fStopItem = new BMenuItem("Stop", new BMessage(MSG_STOP), 'K')); + fStopItem->SetEnabled(false); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Close", new BMessage(MSG_CLOSE), 'W')); + fBar->AddItem(menu); + + menu = new BMenu("Edit"); + menu->AddItem(fPreferencesItem = new BMenuItem("Preferences...", new BMessage(MSG_PREFERENCES), 'P')); + fBar->AddItem(menu); + AddChild(fBar); + + BRect rect = Bounds(); + rect.top += fBar->Bounds().Height() + 1; + BBox *box = new BBox(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); + AddChild(box); + + rect = BRect(10, 10, 75, 25); + fSourceButton = new BButton(rect, "sourceButton", "Source", + new BMessage(MSG_SOURCE), B_FOLLOW_LEFT | B_FOLLOW_TOP); + box->AddChild(fSourceButton); + rect.OffsetBy(0, 28); + fDestButton = new BButton(rect, "destButton", "Destination", + new BMessage(MSG_DEST), B_FOLLOW_LEFT | B_FOLLOW_TOP); + box->AddChild(fDestButton); + rect.OffsetBy(0, 28); + fExpandButton = new BButton(rect, "expandButton", "Expand", + new BMessage(MSG_EXPAND), B_FOLLOW_LEFT | B_FOLLOW_TOP); + box->AddChild(fExpandButton); + fExpandButton->SetEnabled(false); + + rect = BRect(80, 12, Bounds().right - 10, 25); + fSourceText = new BTextControl(rect, "sourceText", "", NULL, + new BMessage(MSG_SOURCETEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + fSourceText->SetDivider(0); + box->AddChild(fSourceText); + + rect.OffsetBy(0, 28); + fDestText = new BTextControl(rect, "destText", "", NULL, + new BMessage(MSG_DESTTEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + fDestText->SetDivider(0); + box->AddChild(fDestText); + + BRect frameRect = rect.OffsetByCopy(0, 27); + frameRect.left += 4; + frameRect.right = frameRect.left + 250; + BRect textRect(frameRect); + textRect.OffsetTo(B_ORIGIN); + textRect.InsetBy(1,1); + fExpandedText = new BTextView(frameRect, "expandedText", textRect, + be_plain_font, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); + fExpandedText->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fExpandedText->MakeEditable(false); + fExpandedText->MakeSelectable(false); + box->AddChild(fExpandedText); + fExpandedText->SetText(""); + + rect = BRect(Bounds().right - 105, rect.bottom + 13, Bounds().right - 10, rect.bottom + 28); + fShowContents = new BCheckBox(rect, "showContents", "Show Contents", + new BMessage(MSG_SHOWCONTENTS), B_FOLLOW_RIGHT | B_FOLLOW_TOP); + box->AddChild(fShowContents); + fShowContents->SetEnabled(false); + + frameRect = Bounds(); + frameRect.InsetBy(10, 0); + frameRect.top += frameRect.Height() - 21; + frameRect.bottom = frameRect.top + 100; + frameRect.right -= B_V_SCROLL_BAR_WIDTH; + + textRect = frameRect; + textRect.OffsetTo(B_ORIGIN); + textRect.InsetBy(1,1); + fListingText = new BTextView(frameRect, "listingText", textRect, + be_fixed_font, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS); + fListingText->SetText(""); + fListingText->MakeEditable(false); + fListingScroll = new BScrollView("listingScroll", fListingText, + B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true); + box->AddChild(fListingScroll); + fListingScroll->Hide(); + + SetSizeLimits(450, BScreen().Frame().Width(), 120, 120); + + // finish creating window + Show(); +} + +ExpanderWindow::~ExpanderWindow() +{ +} + +void +ExpanderWindow::FrameResized(float width, float height) +{ + if (fListingText->DoesWordWrap()) { + BRect textRect; + textRect = fListingText->Bounds(); + textRect.OffsetTo(B_ORIGIN); + textRect.InsetBy(1,1); + fListingText->SetTextRect(textRect); + } +} + +void +ExpanderWindow::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case MSG_SOURCE: + if (!fSourcePanel) + fSourcePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL, + B_FILE_NODE, false, NULL, new RuleRefFilter(fRules), true); + fSourcePanel->Show(); + break; + case MSG_DEST: + if (!fDestPanel) + fDestPanel = new DirectoryFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL, + B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter(), true); + fDestPanel->Show(); + break; + case MSG_DIRECTORY: + { + entry_ref ref; + fDestPanel->GetPanelDirectory(&ref); + fDestRef = ref; + BEntry entry(&ref); + BPath path(&entry); + fDestText->SetText(path.Path()); + fDestPanel->Hide(); + } + break; + case B_SIMPLE_DATA: + case B_REFS_RECEIVED: + { + RefsReceived(msg); + break; + } + case MSG_CLOSE: + PostMessage(B_QUIT_REQUESTED); + break; + case MSG_EXPAND: + if (!fExpandingStarted) { + StartExpanding(); + break; + } + case MSG_STOP: + if (fExpandingStarted) { + fExpandingThread->SuspendExternalExpander(); + BAlert *alert = new BAlert("stopAlert", "Are you sure you want to stop expanding this\n" + "archive? The expanded items may not be complete.", "Stop", "Continue", NULL, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); + if (alert->Go()==0) { + fExpandingThread->ResumeExternalExpander(); + StopExpanding(); + } else + fExpandingThread->ResumeExternalExpander(); + } + break; + case MSG_SHOW: + fShowContents->SetValue(fShowContents->Value() == B_CONTROL_OFF ? B_CONTROL_ON : B_CONTROL_OFF); + fShowItem->SetLabel(fShowContents->Value() == B_CONTROL_OFF ? "Show Contents" : "Hide Contents"); + case MSG_SHOWCONTENTS: + if (fShowContents->Value() == B_CONTROL_OFF) { + if (fListingStarted) + StopListing(); + SetSizeLimits(450, BScreen().Frame().Width(), 120, 120); + ResizeTo(Frame().Width(), 120); + fShowItem->SetLabel("Show Contents"); + } else + StartListing(); + break; + case MSG_SOURCETEXT: + { + BEntry entry(fSourceText->Text(), true); + if (!entry.Exists()) { + BAlert *alert = new BAlert("srcAlert", "The file doesn't exist", + "Cancel", NULL, NULL, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); + alert->Go(); + break; + } + + entry_ref ref; + entry.GetRef(&ref); + ExpanderRule *rule = fRules.MatchingRule(&ref); + if (rule) { + fSourceChanged = true; + fSourceRef = ref; + fShowContents->SetEnabled(true); + fExpandButton->SetEnabled(true); + fExpandItem->SetEnabled(true); + fShowItem->SetEnabled(true); + break; + } + + BString string = "The file : "; + string += fSourceText->Text(); + string += " is not supported"; + BAlert *alert = new BAlert("srcAlert", string.String(), + "Cancel", NULL, NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT); + alert->Go(); + + fShowContents->SetEnabled(false); + fExpandButton->SetEnabled(false); + fExpandItem->SetEnabled(false); + fShowItem->SetEnabled(false); + } + break; + case MSG_DESTTEXT: + { + BEntry entry(fDestText->Text(), true); + if (!entry.Exists()) { + BAlert *alert = new BAlert("destAlert", "The directory was either moved, renamed or not\n" + "supported.", + "Cancel", NULL, NULL, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); + alert->Go(); + break; + } + entry.GetRef(&fDestRef); + } + break; + case MSG_PREFERENCES: + if (!fPreferences) + fPreferences = new ExpanderPreferences(&fSettings); + fPreferences->Show(); + break; + case 'outp': + if (!fExpandingStarted && fListingStarted) { + BString string; + int32 i=0; + while (msg->FindString("output", i++, &string)==B_OK) + fListingText->Insert(string.String()); + fListingText->ScrollToSelection(); + } + + break; + case 'exit': // thread has finished (finished, quit, killed, we don't know) + // reset window state + if (fExpandingStarted) { + fExpandedText->SetText("File expanded"); + StopExpanding(); + OpenDestFolder(); + CloseWindowOrKeepOpen(); + } else if (fListingStarted){ + fSourceChanged = false; + StopListing(); + } else + fExpandedText->SetText(""); + break; + case 'exrr': // thread has finished + // reset window state + + fExpandedText->SetText("Error when expanding archive"); + CloseWindowOrKeepOpen(); + break; + default: + BWindow::MessageReceived(msg); + break; + } +} + +bool +ExpanderWindow::CanQuit() +{ + if ((fSourcePanel && fSourcePanel->IsShowing()) + || (fDestPanel && fDestPanel->IsShowing())) + return false; + + if (fExpandingStarted) { + fExpandingThread->SuspendExternalExpander(); + BAlert *alert = new BAlert("stopAlert", "Are you sure you want to stop expanding this\n" + "archive? The expanded items may not be complete.", "Stop", "Continue", NULL, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); + if (alert->Go()==0) { + fExpandingThread->ResumeExternalExpander(); + StopExpanding(); + } else { + fExpandingThread->ResumeExternalExpander(); + return false; + } + } + return true; +} + +bool +ExpanderWindow::QuitRequested() +{ + if (!CanQuit()) + return false; + + if (fListingStarted) { + StopListing(); + } + + be_app->PostMessage(B_QUIT_REQUESTED); + fSettings.ReplacePoint("window_position", Frame().LeftTop()); + ((ExpanderApp*)(be_app))->UpdateSettingsFrom(&fSettings); + return true; +} + +void +ExpanderWindow::RefsReceived(BMessage *msg) +{ + entry_ref ref; + int32 i = 0; + int8 destination_folder = 0x63; + fSettings.FindInt8("destination_folder", &destination_folder); + + while (msg->FindRef("refs", i++, &ref) == B_OK) { + + BEntry entry(&ref, true); + BPath path(&entry); + BNode node(&entry); + + if (node.IsFile()) { + fSourceChanged = true; + fSourceRef = ref; + fSourceText->SetText(path.Path()); + if (destination_folder==0x63 && strcmp(fDestText->Text(), "")==0) { + BPath parent; + path.GetParent(&parent); + fDestText->SetText(parent.Path()); + get_ref_for_path(parent.Path(), &fDestRef); + } else if (destination_folder==0x65) { + fSettings.FindRef("destination_folder_use", &fDestRef); + BEntry dEntry(&fDestRef, true); + BPath dPath(&dEntry); + fDestText->SetText(dPath.Path()); + } + fShowContents->SetEnabled(true); + fExpandButton->SetEnabled(true); + fExpandItem->SetEnabled(true); + fShowItem->SetEnabled(true); + + bool fromApp; + if (msg->FindBool("fromApp", &fromApp)==B_OK) { + AutoExpand(); + } else + AutoListing(); + } else if(node.IsDirectory()) { + fDestRef = ref; + fDestText->SetText(path.Path()); + } + } +} + +void +ExpanderWindow::StartExpanding() +{ + BMessage message; + + ExpanderRule *rule = fRules.MatchingRule(&fSourceRef); + if (!rule) { + return; + } + + BEntry destEntry(fDestText->Text(), true); + if (!destEntry.Exists()) { + BAlert *alert = new BAlert("destAlert", "The directory was either moved, renamed or not\n" + "supported.", + "Cancel", NULL, NULL, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); + alert->Go(); + return; + } + + message.AddString("cmd", rule->ExpandCmd()); + message.AddRef("srcRef", &fSourceRef); + message.AddRef("destRef", &fDestRef); + + fExpandButton->SetLabel("Stop"); + fSourceButton->SetEnabled(false); + fDestButton->SetEnabled(false); + fShowContents->SetEnabled(false); + fSourceItem->SetEnabled(false); + fDestItem->SetEnabled(false); + fExpandItem->SetEnabled(false); + fShowItem->SetEnabled(false); + fStopItem->SetEnabled(true); + fPreferencesItem->SetEnabled(false); + + BEntry entry(&fSourceRef); + BPath path(&entry); + BString text("Expanding file "); + text.Append(path.Leaf()); + fExpandedText->SetText(text.String()); + + fExpandingThread = new ExpanderThread(&message, new BMessenger(this)); + fExpandingThread->Start(); + + fExpandingStarted = true; +} + +void +ExpanderWindow::StopExpanding(void) +{ + if (fExpandingThread) { + fExpandingThread->InterruptExternalExpander(); + fExpandingThread = NULL; + } + + fExpandingStarted = false; + + fExpandButton->SetLabel("Expand"); + fSourceButton->SetEnabled(true); + fDestButton->SetEnabled(true); + fShowContents->SetEnabled(true); + fSourceItem->SetEnabled(true); + fDestItem->SetEnabled(true); + fExpandItem->SetEnabled(true); + fShowItem->SetEnabled(true); + fStopItem->SetEnabled(false); + fPreferencesItem->SetEnabled(true); +} + +void +ExpanderWindow::StartListing() +{ + SetSizeLimits(450, BScreen().Frame().Width(), 335, BScreen().Frame().Height()); + ResizeTo(Frame().Width(), 335); + fListingScroll->ResizeTo(fListingScroll->Bounds().Width(), 210); + if (fListingScroll->IsHidden()) + fListingScroll->Show(); + + if (!fSourceChanged) + return; + + BMessage message; + + ExpanderRule *rule = fRules.MatchingRule(&fSourceRef); + if (!rule) { + return; + } + message.AddString("cmd", rule->ListingCmd()); + message.AddRef("srcRef", &fSourceRef); + message.AddRef("destRef", &fDestRef); + + fShowContents->SetEnabled(true); + fSourceItem->SetEnabled(false); + fDestItem->SetEnabled(false); + fExpandItem->SetEnabled(false); + fShowItem->SetEnabled(true); + fShowItem->SetLabel("Hide Contents"); + fStopItem->SetEnabled(false); + fPreferencesItem->SetEnabled(false); + + fSourceButton->SetEnabled(false); + fDestButton->SetEnabled(false); + fExpandButton->SetEnabled(false); + + BEntry entry(&fSourceRef); + BPath path(&entry); + BString text("Creating listing for "); + text.Append(path.Leaf()); + fExpandedText->SetText(text.String()); + fListingText->SetText(""); + + fListingThread = new ExpanderThread(&message, new BMessenger(this)); + fListingThread->Start(); + + fListingStarted = true; +} + +void +ExpanderWindow::StopListing(void) +{ + if (fListingThread) { + fListingThread->InterruptExternalExpander(); + fListingThread = NULL; + } + + fListingStarted = false; + + fShowContents->SetEnabled(true); + fSourceItem->SetEnabled(true); + fDestItem->SetEnabled(true); + fExpandItem->SetEnabled(true); + fShowItem->SetEnabled(true); + fStopItem->SetEnabled(false); + fPreferencesItem->SetEnabled(true); + + fSourceButton->SetEnabled(true); + fDestButton->SetEnabled(true); + fExpandButton->SetEnabled(true); + fExpandedText->SetText(""); +} + +void +ExpanderWindow::CloseWindowOrKeepOpen() +{ + bool automatically_expand_files = false; + fSettings.FindBool("automatically_expand_files", &automatically_expand_files); + bool close_when_done = false; + fSettings.FindBool("close_when_done", &close_when_done); + if (automatically_expand_files || close_when_done) + PostMessage(B_QUIT_REQUESTED); +} + +void +ExpanderWindow::OpenDestFolder() +{ + bool open_destination_folder = true; + fSettings.FindBool("open_destination_folder", &open_destination_folder); + + if (!open_destination_folder) + return; + + BMessage * message = new BMessage(B_REFS_RECEIVED); + message->AddRef("refs", &fDestRef); + BPath path(&fDestRef); + BMessenger tracker( "application/x-vnd.Be-TRAK" ); + tracker.SendMessage( message ); +} + +void +ExpanderWindow::AutoListing() +{ + bool show_contents_listing = false; + fSettings.FindBool("show_contents_listing", &show_contents_listing); + + if (!show_contents_listing) + return; + + fShowContents->SetValue(B_CONTROL_ON); + fShowContents->Invoke(); +} + +void +ExpanderWindow::AutoExpand() +{ + bool automatically_expand_files = false; + fSettings.FindBool("automatically_expand_files", &automatically_expand_files); + + if (!automatically_expand_files) { + AutoListing(); + return; + } + + fExpandButton->Invoke(); +} diff --git a/src/apps/expander/ExpanderWindow.h b/src/apps/expander/ExpanderWindow.h new file mode 100644 index 0000000000..7166ca43ce --- /dev/null +++ b/src/apps/expander/ExpanderWindow.h @@ -0,0 +1,94 @@ +/*****************************************************************************/ +// Expander +// Written by Jérôme Duval +// +// ExpanderWindow.h +// +// +// Copyright (c) 2004 OpenBeOS Project +// +// 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 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 MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS 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. +/*****************************************************************************/ + +#ifndef _ExpanderWindow_h +#define _ExpanderWindow_h + +#include +#include +#include +#include +#include +#include "DirectoryFilePanel.h" +#include "ExpanderRules.h" + +class ExpanderThread; +class ExpanderPreferences; + +class ExpanderWindow : public BWindow { +public: + ExpanderWindow(BRect frameRect, const entry_ref *ref, BMessage *settings); + virtual ~ExpanderWindow(); + + virtual void FrameResized(float width, float height); + virtual void MessageReceived(BMessage *msg); + virtual bool QuitRequested(); + + void SetRef(const entry_ref *ref); + void RefsReceived(BMessage *msg); + +private: + bool CanQuit(); + // returns true if the window can be closed safely, false if not + void CloseWindowOrKeepOpen(); + void OpenDestFolder(); + void AutoListing(); + void AutoExpand(); + void StartExpanding(); + void StopExpanding(); + void StartListing(); + void StopListing(); + + BFilePanel *fSourcePanel; + DirectoryFilePanel *fDestPanel; + BMenuBar *fBar; + BMenu *fMenu; + entry_ref fSourceRef; + entry_ref fDestRef; + bool fSourceChanged; + + BButton *fSourceButton, *fDestButton, *fExpandButton; + BMenuItem *fExpandItem, *fShowItem, *fStopItem, + *fSourceItem, *fDestItem, *fPreferencesItem; + BCheckBox *fShowContents; + BTextControl *fSourceText, *fDestText; + BTextView *fExpandedText, *fListingText; + BScrollView *fListingScroll; + + ExpanderThread *fListingThread; + bool fListingStarted; + + ExpanderThread *fExpandingThread; + bool fExpandingStarted; + + BMessage fSettings; + ExpanderPreferences *fPreferences; + ExpanderRules fRules; +}; + +#endif /* _ExpanderWindow_h */ diff --git a/src/apps/expander/GenericThread.cpp b/src/apps/expander/GenericThread.cpp new file mode 100644 index 0000000000..3006520817 --- /dev/null +++ b/src/apps/expander/GenericThread.cpp @@ -0,0 +1,386 @@ +// license: public domain +// authors: jonas.sundstrom@kirilla.com + +#include + +GenericThread::GenericThread(const char * a_thread_name, int32 a_priority, BMessage * a_message) + : + m_thread_data_store (a_message), + m_thread_id (spawn_thread (private_thread_function, a_thread_name, a_priority, this)), + m_execute_unit (create_sem(1, "m_execute_unit")), + m_quit_requested (false), + m_thread_is_paused (false) +{ + if (m_thread_data_store == NULL) + m_thread_data_store = new BMessage(); +} + +GenericThread::~GenericThread() +{ + kill_thread(m_thread_id); + + delete_sem(m_execute_unit); +} + +status_t +GenericThread::ThreadFunction (void) +{ + status_t status = B_OK; + + status = ThreadStartup(); // Subclass and override this function + if (status != B_OK) + { + ThreadStartupFailed (status); + return (status); + // is this the right thing to do? + } + + while(1) + { + if (HasQuitBeenRequested()) + { + status = ThreadShutdown(); // Subclass and override this function + if (status != B_OK) + { + ThreadShutdownFailed (status); + return (status); + // what do we do? + } + + delete this; // destructor + } + + BeginUnit(); + + status = ExecuteUnit(); // Subclass and override + + if (status != B_OK) + ExecuteUnitFailed (status); // Subclass and override + + EndUnit(); + } + + return (B_OK); +} + +status_t +GenericThread::ThreadStartup (void) +{ + // This function is virtual. + // Subclass and override this function. + + return B_OK; +} + + +status_t +GenericThread::ExecuteUnit (void) +{ + // This function is virtual. + + // You would normally subclass and override this function + // as it will provide you with Pause and Quit functionality + // thanks to the unit management done by GenericThread::ThreadFunction() + + return B_OK; +} + +status_t +GenericThread::ThreadShutdown (void) +{ + // This function is virtual. + // Subclass and override this function. + + return B_OK; +} + +void +GenericThread::ThreadStartupFailed (status_t a_status) +{ + // This function is virtual. + // Subclass and override this function. + + Quit(); +} + +void +GenericThread::ExecuteUnitFailed (status_t a_status) +{ + // This function is virtual. + // Subclass and override this function. + + Quit(); +} + +void +GenericThread::ThreadShutdownFailed (status_t a_status) +{ + // This function is virtual. + // Subclass and override this function. + + // (is this good default behaviour?) +} + +status_t +GenericThread::Start (void) +{ + status_t status = B_OK; + + if (IsPaused()) + { + status = release_sem (m_execute_unit); + if (status != B_OK) + return status; + + m_thread_is_paused = false; + } + + status = resume_thread (m_thread_id); + + return status; +} + +int32 +GenericThread::private_thread_function (void * a_simple_thread_ptr) +{ + status_t status = B_OK; + + status = ((GenericThread *) a_simple_thread_ptr)-> ThreadFunction(); + + return (status); +} + +BMessage * +GenericThread::GetDataStore (void) +{ + return (m_thread_data_store); +} + +void +GenericThread::SetDataStore (BMessage * a_message) +{ + m_thread_data_store = a_message; +} + +status_t +GenericThread::Pause (bool a_do_block, bigtime_t a_timeout) +{ + status_t status = B_OK; + + if (a_do_block) + status = acquire_sem(m_execute_unit); + // thread will wait on semaphore + else + status = acquire_sem_etc(m_execute_unit, 1, B_RELATIVE_TIMEOUT, a_timeout); + // thread will timeout + + if (status == B_OK) + { + m_thread_is_paused = true; + return (B_OK); + } + + return status; +} + +void +GenericThread::Quit (void) +{ + m_quit_requested = true; +} + +bool +GenericThread::HasQuitBeenRequested (void) +{ + return (m_quit_requested); +} + +bool +GenericThread::IsPaused (void) +{ + return (m_thread_is_paused); +} + +status_t +GenericThread::Suspend (void) +{ + return (suspend_thread(m_thread_id)); +} + +status_t +GenericThread::Resume (void) +{ + release_sem(m_execute_unit); // to counteract Pause() + m_thread_is_paused = false; + + return (resume_thread(m_thread_id)); // to counteract Suspend() +} + +status_t +GenericThread::Kill (void) +{ + return (kill_thread(m_thread_id)); +} + +void +GenericThread::ExitWithReturnValue (status_t a_return_value) +{ + exit_thread(a_return_value); +} + +status_t +GenericThread::SetExitCallback (void (*a_callback)(void*), void * a_data) +{ + return (on_exit_thread(a_callback, a_data)); +} + +status_t +GenericThread::WaitForThread (status_t * a_exit_value) +{ + return (wait_for_thread(m_thread_id, a_exit_value)); +} + +status_t +GenericThread::Rename (char * a_name) +{ + return (rename_thread(m_thread_id, a_name)); +} + +status_t +GenericThread::SendData (int32 a_code, void * a_buffer, size_t a_buffer_size) +{ + return (send_data(m_thread_id, a_code, a_buffer, a_buffer_size)); +} + +int32 +GenericThread::ReceiveData (thread_id * a_sender, void * a_buffer, size_t a_buffer_size) +{ + return (receive_data(a_sender, a_buffer, a_buffer_size)); +} + +bool +GenericThread::HasData (void) +{ + return (has_data(m_thread_id)); +} + +status_t +GenericThread::SetPriority (int32 a_new_priority) +{ + return (set_thread_priority(m_thread_id, a_new_priority)); +} + +void +GenericThread::Snooze (bigtime_t a_microseconds) +{ + Suspend(); + snooze(a_microseconds); + Resume(); +} + +void +GenericThread::SnoozeUntil (bigtime_t a_microseconds, int a_timebase) +{ + Suspend(); + snooze_until(a_microseconds, a_timebase); + Resume(); +} + +status_t +GenericThread::GetInfo (thread_info * a_thread_info) +{ + return (get_thread_info(m_thread_id, a_thread_info)); +} + +thread_id +GenericThread::GetThread (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.thread); +} + +team_id +GenericThread::GetTeam (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.team); +} + +char * +GenericThread::GetName (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.name); +} + +thread_state +GenericThread::GetState (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.state); +} + +sem_id +GenericThread::GetSemaphore (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.sem); +} + +int32 +GenericThread::GetPriority (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.priority); +} + +bigtime_t +GenericThread::GetUserTime (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.user_time); +} + +bigtime_t +GenericThread::GetKernelTime (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.kernel_time); +} + +void * +GenericThread::GetStackBase (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.stack_base); +} + +void * +GenericThread::GetStackEnd (void) +{ + thread_info t_thread_info; + GetInfo (& t_thread_info); + return (t_thread_info.stack_end); +} + +void +GenericThread::BeginUnit (void) +{ + acquire_sem(m_execute_unit); // thread can not be paused until it releases semaphore +} + +void +GenericThread::EndUnit (void) +{ + release_sem(m_execute_unit); // thread can now be paused +} + diff --git a/src/apps/expander/GenericThread.h b/src/apps/expander/GenericThread.h new file mode 100644 index 0000000000..3a2d8c698b --- /dev/null +++ b/src/apps/expander/GenericThread.h @@ -0,0 +1,83 @@ +#ifndef __GENERIC_THREAD_H__ +#define __GENERIC_THREAD_H__ + +#include +#include + +class GenericThread +{ + public: + GenericThread (const char * a_thread_name = "generic_thread", int32 a_priority = B_NORMAL_PRIORITY, BMessage * a_message = NULL); + virtual ~GenericThread (void); + + BMessage * GetDataStore (void); + void SetDataStore (BMessage * a_message); + + status_t Start (void); + status_t Pause (bool a_do_block = TRUE, bigtime_t a_timeout = 0); + void Quit (void); + bool IsPaused (void); + bool HasQuitBeenRequested (void); + + status_t Suspend (void); + status_t Resume (void); + status_t Kill (void); + + void ExitWithReturnValue (status_t a_return_value); + status_t SetExitCallback (void (* a_callback)(void *), void * a_data); + status_t WaitForThread (status_t * a_exit_value); + + status_t Rename (char * a_name); + + status_t SendData (int32 a_code, void * a_buffer, size_t a_buffer_size); + int32 ReceiveData (thread_id * a_sender, void * a_buffer, size_t a_buffer_size); + bool HasData (void); + + status_t SetPriority (int32 a_new_priority); + + void Snooze (bigtime_t a_microseconds); + void SnoozeUntil (bigtime_t a_microseconds, int a_timebase = B_SYSTEM_TIMEBASE); + + + status_t GetInfo (thread_info * a_thread_info); + thread_id GetThread (void); + team_id GetTeam (void); + char * GetName (void); + thread_state GetState (void); + sem_id GetSemaphore (void); + int32 GetPriority (void); + bigtime_t GetUserTime (void); + bigtime_t GetKernelTime (void); + void * GetStackBase (void); + void * GetStackEnd (void); + + protected: + + virtual status_t ThreadFunction (void); + virtual status_t ThreadStartup (void); + virtual status_t ExecuteUnit (void); + virtual status_t ThreadShutdown (void); + + virtual void ThreadStartupFailed (status_t a_status); + virtual void ExecuteUnitFailed (status_t a_status); + virtual void ThreadShutdownFailed (status_t a_status); + + void BeginUnit (void); // acquire m_execute_cycle + void EndUnit (void); // release m_execute_cycle + + BMessage * m_thread_data_store; + + private: + + static status_t private_thread_function (void * a_simple_thread_ptr); + + thread_id m_thread_id; + + sem_id m_execute_unit; // acq./relase within tread_function.. For Pause() + + bool m_quit_requested; + bool m_thread_is_paused; + +}; + +#endif diff --git a/src/apps/expander/Jamfile b/src/apps/expander/Jamfile new file mode 100644 index 0000000000..49bdac2adc --- /dev/null +++ b/src/apps/expander/Jamfile @@ -0,0 +1,16 @@ +SubDir OBOS_TOP src apps expander ; + +AddResources Expander : Expander.rdef ; + +App Expander : + ExpanderApp.cpp + ExpanderWindow.cpp + ExpanderThread.cpp + GenericThread.cpp + ExpanderSettings.cpp + ExpanderPreferences.cpp + DirectoryFilePanel.cpp + ExpanderRules.cpp ; + +LinkSharedOSLibs Expander : be tracker ; +