-
Notifications
You must be signed in to change notification settings - Fork 4
/
App.cpp
157 lines (133 loc) · 3.13 KB
/
App.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright 2011-2015. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Author:
* Humdinger, humdingerb@gmail.com
*/
#include "App.h"
#include "MainWindow.h"
#include <Alert.h>
#include <Catalog.h>
#include <Font.h>
#include <TextView.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "App"
const char *kApplicationSignature = "application/x-vnd.humdinger-ubertuber";
App::App()
:
BApplication("application/x-vnd.humdinger-ubertuber"),
fSavedRefsReceived(NULL),
fURLReceived(NULL)
{
fMainWindow = new MainWindow();
fMainWindow->Show();
}
App::~App()
{
delete fSavedRefsReceived;
delete fURLReceived;
}
void
App::ArgvReceived(int32 argc, char** argv)
{
if (strcmp(argv[1], "--help") == 0
|| strcmp(argv[1], "-h") == 0) {
printf(B_TRANSLATE("UberTuber can be launched with either a URL or a "
"Web+ Bookmark file.\n"));
PostMessage(B_QUIT_REQUESTED);
return;
}
BMessage refsReceived(B_REFS_RECEIVED);
BEntry entry(argv[1], true);
entry_ref ref;
if (entry.GetRef(&ref) == B_OK)
refsReceived.AddRef("refs", &ref);
if (refsReceived.HasRef("refs"))
PostMessage(&refsReceived);
else
fURLReceived = new BString(argv[1]);
}
void
App::RefsReceived(BMessage* message)
{
if (!message->HasRef("refs") && message->HasRef("dir_ref")) {
entry_ref dirRef;
if (message->FindRef("dir_ref", &dirRef) == B_OK)
message->AddRef("refs", &dirRef);
}
if (fMainWindow == NULL) {
// ReadyToRun() has not been called yet, this happens when someone
// launches us with a B_REFS_RECEIVED message.
delete fSavedRefsReceived;
fSavedRefsReceived = new BMessage(*message);
} else
fMainWindow->PostMessage(message);
}
void
App::MessageReceived(BMessage* message)
{
switch (message->what)
{
case statBUFFER:
case statDOWNLOAD:
case statERROR:
case statFINISH_GET:
case statFINISH_PLAY:
case statFINISH_SAVE:
case statPLAYING:
{
fMainWindow->PostMessage(DetachCurrentMessage());
break;
}
default:
{
BApplication::MessageReceived(message);
break;
}
}
}
void
App::ReadyToRun()
{
if (fSavedRefsReceived) {
// RefsReceived() was called earlier than ReadyToRun()
fMainWindow->PostMessage(fSavedRefsReceived);
delete fSavedRefsReceived;
fSavedRefsReceived = NULL;
}
if (fURLReceived){
fMainWindow->LockLooper();
fMainWindow->SetURL(fURLReceived);
fMainWindow->UnlockLooper();
}
}
void
App::AboutRequested()
{
BAlert* alert = new BAlert("about", B_TRANSLATE("UberTuber v0.9.11\n"
"\twritten by Humdinger\n"
"\tbased on ideas of Leszek's YAVTD\n"
"\tCopyright 2011-2015\n\n"
"UberTuber uses a script to download YouTube videos.\n"
"Clips can be saved or played back directly. UberTuber monitors "
"the system clipboard for newly copied URLs and has an 'Auto-play' "
"option that'll start playback as soon as a supported URL is detected.\n"),
B_TRANSLATE("Thank you"));
BTextView* view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetSize(font.Size()+4);
font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, 9, &font);
alert->Go();
}
int
main()
{
App* app = new App();
app->Run();
delete app;
return 0;
}