HaikuDepot: notify work status from main window
[haiku.git] / src / apps / packageinstaller / main.cpp
blob2cc83cde304c92b33af71e60544edc72caebab3b
1 /*
2 * Copyright (c) 2007-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * Ɓukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7 */
9 #include "main.h"
11 #include "PackageWindow.h"
12 #include "UninstallWindow.h"
14 #include <Alert.h>
15 #include <Application.h>
16 #include <Autolock.h>
17 #include <Catalog.h>
18 #include <Entry.h>
19 #include <List.h>
20 #include <Locale.h>
21 #include <Path.h>
22 #include <TextView.h>
24 #include <stdio.h>
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "Packageinstaller main"
31 bool gVerbose = false;
34 PackageInstaller::PackageInstaller()
36 BApplication("application/x-vnd.Haiku-PackageInstaller"),
37 fWindowCount(0)
42 PackageInstaller::~PackageInstaller()
47 void
48 PackageInstaller::ReadyToRun()
50 // We're ready to run - if no windows are yet visible, this means that
51 // we should show the UninstallWindow
52 if (fWindowCount == 0) {
53 (new UninstallWindow)->Show();
54 fWindowCount++;
59 void
60 PackageInstaller::RefsReceived(BMessage* message)
62 entry_ref ref;
63 for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++)
64 _NewWindow(&ref);
68 void
69 PackageInstaller::ArgvReceived(int32 argc, char** argv)
71 for (int i = 1; i < argc; i++) {
72 if (strcmp("--verbose", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) {
73 gVerbose = true;
74 continue;
77 BPath path;
78 if (path.SetTo(argv[i]) != B_OK) {
79 fprintf(stderr, B_TRANSLATE("Error! \"%s\" is not a valid path.\n"),
80 argv[i]);
81 continue;
84 entry_ref ref;
85 status_t ret = get_ref_for_path(path.Path(), &ref);
86 if (ret != B_OK) {
87 fprintf(stderr, B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"),
88 strerror(ret), argv[i]);
89 continue;
92 _NewWindow(&ref);
97 void
98 PackageInstaller::MessageReceived(BMessage* message)
100 switch (message->what) {
101 case P_WINDOW_QUIT:
102 fWindowCount--;
103 // fall through
104 case B_CANCEL:
105 if (fWindowCount == 0)
106 PostMessage(B_QUIT_REQUESTED);
107 break;
109 default:
110 BApplication::MessageReceived(message);
115 void
116 PackageInstaller::_NewWindow(const entry_ref* ref)
118 PackageWindow* window = new PackageWindow(ref);
119 window->Show();
121 fWindowCount++;
126 main(void)
128 PackageInstaller app;
129 app.Run();
131 return 0;