This repository has been archived by the owner on Jan 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
89 lines (67 loc) · 2.38 KB
/
main.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
#include <QCoreApplication>
#include <Utils/contrib/SingleApplication/singleapplication.h>
#include <applicationmanager.hpp>
#include "Utils/range_based_for_loop.hpp"
#include <iostream>
#include <sys/ioctl.h>
static void print_header()
{
// escape sequences
static const std::string term_reset = "\033[0m";
static const std::string term_bold = "\033[1m";
struct winsize w;
int cols(0);
// get amount of columns of the active terminal window
if (ioctl(0, TIOCGWINSZ, &w) != -1)
cols = w.ws_col;
std::string line;
std::string header;
// generate nice header with separator line across terminal window
if (cols != 0)
{
cols -= 2;
// generate base line
for (int i = 0; i < cols; i++)
line.append("─");
// first line
header.append(term_reset + "┌" + line + "┐\n");
// second line
header.append(
"│ " + term_bold +
qUtf8Printable(QCoreApplication::applicationName()) +
term_reset + ' ' +
qUtf8Printable(QCoreApplication::applicationVersion()));
for (int i = 2 + QCoreApplication::applicationName().size()
+ QCoreApplication::applicationVersion().size(); i < cols; i++)
header.append(" ");
header.append("│\n");
// last line
header.append("└" + line + "┘\n");
}
// generate normal header, eg: for log files
else
{
header.append(
term_reset + term_bold +
qUtf8Printable(QCoreApplication::applicationName()) +
term_reset +
qUtf8Printable(QCoreApplication::applicationVersion()));
}
// print the header
std::cout << header << std::endl;
// clean up
line.clear();
header.clear();
}
int main(int argc, char **argv)
{
QCoreApplication::setApplicationName("Music Console");
QCoreApplication::setApplicationVersion("0.53-6");
QCoreApplication::setOrganizationName("GhettoGirl");
print_header();
SingleApplication a(argc, argv, QObject::trUtf8("\033[1;38;2;166;74;0mNOTICE:\033[0m \033[3monly one instance is allowed!\033[0m"));
ApplicationManager *appInstance = new ApplicationManager();
appInstance->enter();
QObject::connect(&a, &SingleApplication::showUp, appInstance, &ApplicationManager::executeCmd, Qt::QueuedConnection);
return a.exec();
}