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> 2044f919daSRyan Leavengood #include <TextView.h> 21091440e0SStephan Aßmus 2244f919daSRyan Leavengood #include <stdio.h> 2344f919daSRyan Leavengood 24*546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 25*546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Packageinstaller main" 2644f919daSRyan Leavengood 2744f919daSRyan Leavengood class PackageInstaller : public BApplication { 2844f919daSRyan Leavengood public: 2944f919daSRyan Leavengood PackageInstaller(); 3044f919daSRyan Leavengood ~PackageInstaller(); 3144f919daSRyan Leavengood 3244f919daSRyan Leavengood void RefsReceived(BMessage *msg); 3344f919daSRyan Leavengood void ArgvReceived(int32 argc, char **argv); 3444f919daSRyan Leavengood void ReadyToRun(); 3544f919daSRyan Leavengood 3644f919daSRyan Leavengood void MessageReceived(BMessage *msg); 3744f919daSRyan Leavengood 3844f919daSRyan Leavengood private: 3944f919daSRyan Leavengood BFilePanel *fOpen; 4044f919daSRyan Leavengood uint32 fWindowCount; 4144f919daSRyan Leavengood }; 4244f919daSRyan Leavengood 4344f919daSRyan Leavengood 4444f919daSRyan Leavengood PackageInstaller::PackageInstaller() 4544f919daSRyan Leavengood : BApplication("application/x-vnd.Haiku-PackageInstaller"), 46091440e0SStephan Aßmus fOpen(NULL), 47be8fa2fbSAdrien Destugues fWindowCount(0) 4844f919daSRyan Leavengood { 4944f919daSRyan Leavengood fOpen = new BFilePanel(B_OPEN_PANEL); 5044f919daSRyan Leavengood } 5144f919daSRyan Leavengood 5244f919daSRyan Leavengood 5344f919daSRyan Leavengood PackageInstaller::~PackageInstaller() 5444f919daSRyan Leavengood { 5544f919daSRyan Leavengood } 5644f919daSRyan Leavengood 5744f919daSRyan Leavengood 5844f919daSRyan Leavengood void 5944f919daSRyan Leavengood PackageInstaller::ReadyToRun() 6044f919daSRyan Leavengood { 6144f919daSRyan Leavengood // We're ready to run - if no windows are yet visible, this means that 6244f919daSRyan Leavengood // we should show a open panel 6344f919daSRyan Leavengood if (fWindowCount == 0) { 6444f919daSRyan Leavengood fOpen->Show(); 6544f919daSRyan Leavengood } 6644f919daSRyan Leavengood } 6744f919daSRyan Leavengood 6844f919daSRyan Leavengood 6944f919daSRyan Leavengood void 7044f919daSRyan Leavengood PackageInstaller::RefsReceived(BMessage *msg) 7144f919daSRyan Leavengood { 7244f919daSRyan Leavengood uint32 type; 7344f919daSRyan Leavengood int32 i, count; 7444f919daSRyan Leavengood status_t ret = msg->GetInfo("refs", &type, &count); 7544f919daSRyan Leavengood if (ret != B_OK || type != B_REF_TYPE) 7644f919daSRyan Leavengood return; 7744f919daSRyan Leavengood 7844f919daSRyan Leavengood entry_ref ref; 7944f919daSRyan Leavengood PackageWindow *iter; 8044f919daSRyan Leavengood for (i = 0; i < count; i++) { 8144f919daSRyan Leavengood if (msg->FindRef("refs", i, &ref) == B_OK) { 8244f919daSRyan Leavengood iter = new PackageWindow(&ref); 8344f919daSRyan Leavengood fWindowCount++; 8444f919daSRyan Leavengood iter->Show(); 8544f919daSRyan Leavengood } 8644f919daSRyan Leavengood } 8744f919daSRyan Leavengood } 8844f919daSRyan Leavengood 8944f919daSRyan Leavengood 9044f919daSRyan Leavengood void 9144f919daSRyan Leavengood PackageInstaller::ArgvReceived(int32 argc, char **argv) 9244f919daSRyan Leavengood { 9344f919daSRyan Leavengood int i; 9444f919daSRyan Leavengood BPath path; 9544f919daSRyan Leavengood entry_ref ref; 9644f919daSRyan Leavengood status_t ret = B_OK; 9744f919daSRyan Leavengood PackageWindow *iter = 0; 9844f919daSRyan Leavengood 9944f919daSRyan Leavengood for (i = 1; i < argc; i++) { 10044f919daSRyan Leavengood if (path.SetTo(argv[i]) != B_OK) { 101eef95624SMatt Madia fprintf(stderr, 102eef95624SMatt Madia B_TRANSLATE("Error! \"%s\" is not a valid path.\n"), 103eef95624SMatt Madia argv[i]); 10444f919daSRyan Leavengood continue; 10544f919daSRyan Leavengood } 10644f919daSRyan Leavengood 10744f919daSRyan Leavengood ret = get_ref_for_path(path.Path(), &ref); 10844f919daSRyan Leavengood if (ret != B_OK) { 109eef95624SMatt Madia fprintf(stderr, 110eef95624SMatt Madia B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"), 111eef95624SMatt Madia strerror(ret), argv[i]); 11244f919daSRyan Leavengood continue; 11344f919daSRyan Leavengood } 11444f919daSRyan Leavengood 11544f919daSRyan Leavengood iter = new PackageWindow(&ref); 11644f919daSRyan Leavengood fWindowCount++; 11744f919daSRyan Leavengood iter->Show(); 11844f919daSRyan Leavengood } 11944f919daSRyan Leavengood } 12044f919daSRyan Leavengood 12144f919daSRyan Leavengood 12244f919daSRyan Leavengood void 12344f919daSRyan Leavengood PackageInstaller::MessageReceived(BMessage *msg) 12444f919daSRyan Leavengood { 12544f919daSRyan Leavengood switch (msg->what) { 12644f919daSRyan Leavengood case P_WINDOW_QUIT: 12744f919daSRyan Leavengood fWindowCount--; 128b052daffSRyan Leavengood case B_CANCEL: 12944f919daSRyan Leavengood if (fWindowCount == 0) { 13044f919daSRyan Leavengood BAutolock lock(this); 13144f919daSRyan Leavengood if (lock.IsLocked()) 13244f919daSRyan Leavengood Quit(); 13344f919daSRyan Leavengood } 13444f919daSRyan Leavengood break; 13544f919daSRyan Leavengood default: 13644f919daSRyan Leavengood BApplication::MessageReceived(msg); 13744f919daSRyan Leavengood } 13844f919daSRyan Leavengood } 13944f919daSRyan Leavengood 14044f919daSRyan Leavengood 14144f919daSRyan Leavengood int 14244f919daSRyan Leavengood main(void) 14344f919daSRyan Leavengood { 14444f919daSRyan Leavengood PackageInstaller app; 14544f919daSRyan Leavengood app.Run(); 14644f919daSRyan Leavengood 14744f919daSRyan Leavengood return 0; 14844f919daSRyan Leavengood } 14944f919daSRyan Leavengood 150