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
9*eaf0a567SAugustin Cavalier #include "main.h"
1044f919daSRyan Leavengood
1144f919daSRyan Leavengood #include "PackageWindow.h"
12*eaf0a567SAugustin Cavalier #include "UninstallWindow.h"
1344f919daSRyan Leavengood
14091440e0SStephan Aßmus #include <Alert.h>
1544f919daSRyan Leavengood #include <Application.h>
16091440e0SStephan Aßmus #include <Autolock.h>
17091440e0SStephan Aßmus #include <Catalog.h>
18091440e0SStephan Aßmus #include <Entry.h>
1944f919daSRyan Leavengood #include <List.h>
20091440e0SStephan Aßmus #include <Locale.h>
212a7d988dSStephan Aßmus #include <Path.h>
2244f919daSRyan Leavengood #include <TextView.h>
23091440e0SStephan Aßmus
2444f919daSRyan Leavengood #include <stdio.h>
2544f919daSRyan Leavengood
26bdcd6afcSStephan Aßmus
27546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
28546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Packageinstaller main"
2944f919daSRyan Leavengood
30bdcd6afcSStephan Aßmus
31c3a07a5aSStephan Aßmus bool gVerbose = false;
32c3a07a5aSStephan Aßmus
33c3a07a5aSStephan Aßmus
PackageInstaller()3444f919daSRyan Leavengood PackageInstaller::PackageInstaller()
35bdcd6afcSStephan Aßmus :
36bdcd6afcSStephan Aßmus BApplication("application/x-vnd.Haiku-PackageInstaller"),
37be8fa2fbSAdrien Destugues fWindowCount(0)
3844f919daSRyan Leavengood {
3944f919daSRyan Leavengood }
4044f919daSRyan Leavengood
4144f919daSRyan Leavengood
~PackageInstaller()4244f919daSRyan Leavengood PackageInstaller::~PackageInstaller()
4344f919daSRyan Leavengood {
4444f919daSRyan Leavengood }
4544f919daSRyan Leavengood
4644f919daSRyan Leavengood
4744f919daSRyan Leavengood void
ReadyToRun()4844f919daSRyan Leavengood PackageInstaller::ReadyToRun()
4944f919daSRyan Leavengood {
5044f919daSRyan Leavengood // We're ready to run - if no windows are yet visible, this means that
51*eaf0a567SAugustin Cavalier // we should show the UninstallWindow
52*eaf0a567SAugustin Cavalier if (fWindowCount == 0) {
53*eaf0a567SAugustin Cavalier (new UninstallWindow)->Show();
54*eaf0a567SAugustin Cavalier fWindowCount++;
55*eaf0a567SAugustin Cavalier }
5644f919daSRyan Leavengood }
5744f919daSRyan Leavengood
5844f919daSRyan Leavengood
5944f919daSRyan Leavengood void
RefsReceived(BMessage * message)60bdcd6afcSStephan Aßmus PackageInstaller::RefsReceived(BMessage* message)
6144f919daSRyan Leavengood {
6244f919daSRyan Leavengood entry_ref ref;
63bdcd6afcSStephan Aßmus for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++)
64bdcd6afcSStephan Aßmus _NewWindow(&ref);
6544f919daSRyan Leavengood }
6644f919daSRyan Leavengood
6744f919daSRyan Leavengood
6844f919daSRyan Leavengood void
ArgvReceived(int32 argc,char ** argv)6944f919daSRyan Leavengood PackageInstaller::ArgvReceived(int32 argc, char** argv)
7044f919daSRyan Leavengood {
71bdcd6afcSStephan Aßmus for (int i = 1; i < argc; i++) {
72c3a07a5aSStephan Aßmus if (strcmp("--verbose", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) {
73c3a07a5aSStephan Aßmus gVerbose = true;
74c3a07a5aSStephan Aßmus continue;
75c3a07a5aSStephan Aßmus }
76c3a07a5aSStephan Aßmus
7744f919daSRyan Leavengood BPath path;
7844f919daSRyan Leavengood if (path.SetTo(argv[i]) != B_OK) {
79bdcd6afcSStephan Aßmus fprintf(stderr, B_TRANSLATE("Error! \"%s\" is not a valid path.\n"),
80eef95624SMatt Madia argv[i]);
8144f919daSRyan Leavengood continue;
8244f919daSRyan Leavengood }
8344f919daSRyan Leavengood
84bdcd6afcSStephan Aßmus entry_ref ref;
85bdcd6afcSStephan Aßmus status_t ret = get_ref_for_path(path.Path(), &ref);
8644f919daSRyan Leavengood if (ret != B_OK) {
87bdcd6afcSStephan Aßmus fprintf(stderr, B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"),
88eef95624SMatt Madia strerror(ret), argv[i]);
8944f919daSRyan Leavengood continue;
9044f919daSRyan Leavengood }
9144f919daSRyan Leavengood
92bdcd6afcSStephan Aßmus _NewWindow(&ref);
9344f919daSRyan Leavengood }
9444f919daSRyan Leavengood }
9544f919daSRyan Leavengood
9644f919daSRyan Leavengood
9744f919daSRyan Leavengood void
MessageReceived(BMessage * message)98bdcd6afcSStephan Aßmus PackageInstaller::MessageReceived(BMessage* message)
9944f919daSRyan Leavengood {
100bdcd6afcSStephan Aßmus switch (message->what) {
10144f919daSRyan Leavengood case P_WINDOW_QUIT:
10244f919daSRyan Leavengood fWindowCount--;
103bdcd6afcSStephan Aßmus // fall through
104b052daffSRyan Leavengood case B_CANCEL:
105bdcd6afcSStephan Aßmus if (fWindowCount == 0)
106bdcd6afcSStephan Aßmus PostMessage(B_QUIT_REQUESTED);
10744f919daSRyan Leavengood break;
108bdcd6afcSStephan Aßmus
10944f919daSRyan Leavengood default:
110bdcd6afcSStephan Aßmus BApplication::MessageReceived(message);
11144f919daSRyan Leavengood }
11244f919daSRyan Leavengood }
11344f919daSRyan Leavengood
11444f919daSRyan Leavengood
115bdcd6afcSStephan Aßmus void
_NewWindow(const entry_ref * ref)116bdcd6afcSStephan Aßmus PackageInstaller::_NewWindow(const entry_ref* ref)
117bdcd6afcSStephan Aßmus {
118bdcd6afcSStephan Aßmus PackageWindow* window = new PackageWindow(ref);
119bdcd6afcSStephan Aßmus window->Show();
120bdcd6afcSStephan Aßmus
121bdcd6afcSStephan Aßmus fWindowCount++;
122bdcd6afcSStephan Aßmus }
123bdcd6afcSStephan Aßmus
124bdcd6afcSStephan Aßmus
12544f919daSRyan Leavengood int
main(void)12644f919daSRyan Leavengood main(void)
12744f919daSRyan Leavengood {
12844f919daSRyan Leavengood PackageInstaller app;
12944f919daSRyan Leavengood app.Run();
13044f919daSRyan Leavengood
13144f919daSRyan Leavengood return 0;
13244f919daSRyan Leavengood }
13344f919daSRyan Leavengood
134