144f919daSRyan Leavengood /* 27974d3dcSStephan Aßmus * Copyright (c) 2007-2009, Haiku, Inc. All rights reserved. 344f919daSRyan Leavengood * Distributed under the terms of the MIT license. 444f919daSRyan Leavengood * 544f919daSRyan Leavengood * Author: 644f919daSRyan Leavengood * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> 744f919daSRyan Leavengood */ 844f919daSRyan Leavengood 944f919daSRyan Leavengood 1044f919daSRyan Leavengood #include "PackageWindow.h" 1144f919daSRyan Leavengood 12091440e0SStephan Aßmus #include <Alert.h> 1344f919daSRyan Leavengood #include <Application.h> 14091440e0SStephan Aßmus #include <Autolock.h> 15091440e0SStephan Aßmus #include <Catalog.h> 16091440e0SStephan Aßmus #include <Entry.h> 1744f919daSRyan Leavengood #include <FilePanel.h> 1844f919daSRyan Leavengood #include <List.h> 19091440e0SStephan Aßmus #include <Locale.h> 202a7d988dSStephan Aßmus #include <Path.h> 2144f919daSRyan Leavengood #include <TextView.h> 22091440e0SStephan Aßmus 2344f919daSRyan Leavengood #include <stdio.h> 2444f919daSRyan Leavengood 25bdcd6afcSStephan Aßmus 26546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 27546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Packageinstaller main" 2844f919daSRyan Leavengood 29bdcd6afcSStephan Aßmus 30*c3a07a5aSStephan Aßmus bool gVerbose = false; 31*c3a07a5aSStephan Aßmus 32*c3a07a5aSStephan Aßmus 3344f919daSRyan Leavengood class PackageInstaller : public BApplication { 3444f919daSRyan Leavengood public: 3544f919daSRyan Leavengood PackageInstaller(); 36bdcd6afcSStephan Aßmus virtual ~PackageInstaller(); 3744f919daSRyan Leavengood 38bdcd6afcSStephan Aßmus virtual void RefsReceived(BMessage* message); 39bdcd6afcSStephan Aßmus virtual void ArgvReceived(int32 argc, char** argv); 40bdcd6afcSStephan Aßmus virtual void ReadyToRun(); 4144f919daSRyan Leavengood 42bdcd6afcSStephan Aßmus virtual void MessageReceived(BMessage* message); 4344f919daSRyan Leavengood 4444f919daSRyan Leavengood private: 45bdcd6afcSStephan Aßmus void _NewWindow(const entry_ref* ref); 46bdcd6afcSStephan Aßmus 47bdcd6afcSStephan Aßmus private: 48bdcd6afcSStephan Aßmus BFilePanel* fOpenPanel; 4944f919daSRyan Leavengood uint32 fWindowCount; 5044f919daSRyan Leavengood }; 5144f919daSRyan Leavengood 5244f919daSRyan Leavengood 5344f919daSRyan Leavengood PackageInstaller::PackageInstaller() 54bdcd6afcSStephan Aßmus : 55bdcd6afcSStephan Aßmus BApplication("application/x-vnd.Haiku-PackageInstaller"), 56bdcd6afcSStephan Aßmus fOpenPanel(new BFilePanel(B_OPEN_PANEL)), 57be8fa2fbSAdrien Destugues fWindowCount(0) 5844f919daSRyan Leavengood { 5944f919daSRyan Leavengood } 6044f919daSRyan Leavengood 6144f919daSRyan Leavengood 6244f919daSRyan Leavengood PackageInstaller::~PackageInstaller() 6344f919daSRyan Leavengood { 6444f919daSRyan Leavengood } 6544f919daSRyan Leavengood 6644f919daSRyan Leavengood 6744f919daSRyan Leavengood void 6844f919daSRyan Leavengood PackageInstaller::ReadyToRun() 6944f919daSRyan Leavengood { 7044f919daSRyan Leavengood // We're ready to run - if no windows are yet visible, this means that 7144f919daSRyan Leavengood // we should show a open panel 72bdcd6afcSStephan Aßmus if (fWindowCount == 0) 73bdcd6afcSStephan Aßmus fOpenPanel->Show(); 7444f919daSRyan Leavengood } 7544f919daSRyan Leavengood 7644f919daSRyan Leavengood 7744f919daSRyan Leavengood void 78bdcd6afcSStephan Aßmus PackageInstaller::RefsReceived(BMessage* message) 7944f919daSRyan Leavengood { 8044f919daSRyan Leavengood entry_ref ref; 81bdcd6afcSStephan Aßmus for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) 82bdcd6afcSStephan Aßmus _NewWindow(&ref); 8344f919daSRyan Leavengood } 8444f919daSRyan Leavengood 8544f919daSRyan Leavengood 8644f919daSRyan Leavengood void 8744f919daSRyan Leavengood PackageInstaller::ArgvReceived(int32 argc, char** argv) 8844f919daSRyan Leavengood { 89bdcd6afcSStephan Aßmus for (int i = 1; i < argc; i++) { 90*c3a07a5aSStephan Aßmus if (strcmp("--verbose", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) { 91*c3a07a5aSStephan Aßmus gVerbose = true; 92*c3a07a5aSStephan Aßmus continue; 93*c3a07a5aSStephan Aßmus } 94*c3a07a5aSStephan Aßmus 9544f919daSRyan Leavengood BPath path; 9644f919daSRyan Leavengood if (path.SetTo(argv[i]) != B_OK) { 97bdcd6afcSStephan Aßmus fprintf(stderr, B_TRANSLATE("Error! \"%s\" is not a valid path.\n"), 98eef95624SMatt Madia argv[i]); 9944f919daSRyan Leavengood continue; 10044f919daSRyan Leavengood } 10144f919daSRyan Leavengood 102bdcd6afcSStephan Aßmus entry_ref ref; 103bdcd6afcSStephan Aßmus status_t ret = get_ref_for_path(path.Path(), &ref); 10444f919daSRyan Leavengood if (ret != B_OK) { 105bdcd6afcSStephan Aßmus fprintf(stderr, B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"), 106eef95624SMatt Madia strerror(ret), argv[i]); 10744f919daSRyan Leavengood continue; 10844f919daSRyan Leavengood } 10944f919daSRyan Leavengood 110bdcd6afcSStephan Aßmus _NewWindow(&ref); 11144f919daSRyan Leavengood } 11244f919daSRyan Leavengood } 11344f919daSRyan Leavengood 11444f919daSRyan Leavengood 11544f919daSRyan Leavengood void 116bdcd6afcSStephan Aßmus PackageInstaller::MessageReceived(BMessage* message) 11744f919daSRyan Leavengood { 118bdcd6afcSStephan Aßmus switch (message->what) { 11944f919daSRyan Leavengood case P_WINDOW_QUIT: 12044f919daSRyan Leavengood fWindowCount--; 121bdcd6afcSStephan Aßmus // fall through 122b052daffSRyan Leavengood case B_CANCEL: 123bdcd6afcSStephan Aßmus if (fWindowCount == 0) 124bdcd6afcSStephan Aßmus PostMessage(B_QUIT_REQUESTED); 12544f919daSRyan Leavengood break; 126bdcd6afcSStephan Aßmus 12744f919daSRyan Leavengood default: 128bdcd6afcSStephan Aßmus BApplication::MessageReceived(message); 12944f919daSRyan Leavengood } 13044f919daSRyan Leavengood } 13144f919daSRyan Leavengood 13244f919daSRyan Leavengood 133bdcd6afcSStephan Aßmus void 134bdcd6afcSStephan Aßmus PackageInstaller::_NewWindow(const entry_ref* ref) 135bdcd6afcSStephan Aßmus { 136bdcd6afcSStephan Aßmus PackageWindow* window = new PackageWindow(ref); 137bdcd6afcSStephan Aßmus window->Show(); 138bdcd6afcSStephan Aßmus 139bdcd6afcSStephan Aßmus fWindowCount++; 140bdcd6afcSStephan Aßmus } 141bdcd6afcSStephan Aßmus 142bdcd6afcSStephan Aßmus 14344f919daSRyan Leavengood int 14444f919daSRyan Leavengood main(void) 14544f919daSRyan Leavengood { 14644f919daSRyan Leavengood PackageInstaller app; 14744f919daSRyan Leavengood app.Run(); 14844f919daSRyan Leavengood 14944f919daSRyan Leavengood return 0; 15044f919daSRyan Leavengood } 15144f919daSRyan Leavengood 152