~marcusbritanicus/newbreeze/master

« back to all changes in this revision

Viewing changes to Core/ConfigParser/NBDesktopFile.cpp

  • Committer: Marcus Britanicus
  • Date: 2016-02-10 10:14:27 UTC
  • Revision ID: git-v1:97bf08bb92f6e12ddd42f57effe8411d32e29414
NewBreeze v3.0.0. Obsolete code cleanup. Wed Feb 10 15:44:27 IST 2016

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
        *
3
 
        * NBDesktopFile.cpp - NewBreeze DesktopFile Handler Class
4
 
        *
5
 
*/
6
 
 
7
 
#include <NBDesktopFile.hpp>
8
 
 
9
 
inline QString findIn( QString what, QString where ) {
10
 
 
11
 
        QRegExp rx( what );
12
 
        rx.setMinimal( true );
13
 
 
14
 
        if ( rx.indexIn( where ) >= 0 )
15
 
                return rx.cap( 1 );
16
 
 
17
 
        return QString();
18
 
};
19
 
 
20
 
NBDesktopFile::NBDesktopFile( QString path ) {
21
 
 
22
 
        fileUrl = QString( path );
23
 
        parseDesktopFile();
24
 
};
25
 
 
26
 
QString NBDesktopFile::name() {
27
 
 
28
 
        return __name;
29
 
};
30
 
 
31
 
QString NBDesktopFile::type() {
32
 
 
33
 
        return __type;
34
 
};
35
 
 
36
 
QString NBDesktopFile::exec() {
37
 
 
38
 
        return __exec;
39
 
};
40
 
 
41
 
QString NBDesktopFile::icon() {
42
 
 
43
 
        return __icon;
44
 
};
45
 
 
46
 
QStringList NBDesktopFile::mimeTypes() {
47
 
 
48
 
        return __mimeTypes;
49
 
};
50
 
 
51
 
QString NBDesktopFile::workPath() {
52
 
 
53
 
        return __workPath;
54
 
};
55
 
 
56
 
bool NBDesktopFile::terminalMode() {
57
 
 
58
 
        return __terminalMode;
59
 
};
60
 
 
61
 
QStringList NBDesktopFile::categories() {
62
 
 
63
 
        return __categories;
64
 
};
65
 
 
66
 
QString NBDesktopFile::comment() {
67
 
 
68
 
        return __comment;
69
 
};
70
 
 
71
 
QStringList NBDesktopFile::execArgs() {
72
 
 
73
 
        return __execArgs;
74
 
};
75
 
 
76
 
bool NBDesktopFile::multipleArgs() {
77
 
 
78
 
        return __multipleFiles;
79
 
};
80
 
 
81
 
bool NBDesktopFile::takesArgs() {
82
 
 
83
 
        return __takesArgs;
84
 
};
85
 
 
86
 
short NBDesktopFile::grade() {
87
 
 
88
 
        return __grade;
89
 
};
90
 
 
91
 
QString NBDesktopFile::desktopFileName() {
92
 
 
93
 
        return baseName( fileUrl );
94
 
};
95
 
 
96
 
bool NBDesktopFile::isSameAs( NBDesktopFile other ) {
97
 
 
98
 
        if ( __execArgs.at( 0 ) == other.execArgs().at( 0 ) )
99
 
                return true;
100
 
 
101
 
        return false;
102
 
};
103
 
 
104
 
bool NBDesktopFile::areSame( NBDesktopFile dEntry1, NBDesktopFile dEntry2 ) {
105
 
 
106
 
        if ( dEntry1.execArgs().at( 0 ) == dEntry2.execArgs().at( 0 ) )
107
 
                return true;
108
 
 
109
 
        return false;
110
 
};
111
 
 
112
 
void NBDesktopFile::parseDesktopFile() {
113
 
 
114
 
        QString rxName( "\nName=(.*)(\n|\r\n)" );
115
 
        QString rxType( "\nType=(.*)(\n|\r\n)" );
116
 
        QString rxExec( "\nExec=(.*)(\n|\r\n)" );
117
 
        QString rxIcon( "\nIcon=(.*)(\n|\r\n)" );
118
 
        QString rxPath( "\nPath=(.*)(\n|\r\n)" );
119
 
        QString rxMime( "\nMimeType=(.*)(\n|\r\n)" );
120
 
        QString rxTerm( "\nTerminal=(.*)(\n|\r\n)" );
121
 
        QString rxCate( "\nCategories=(.*)(\n|\r\n)" );
122
 
        QString rxComm( "\nComment=(.*)(\n|\r\n)" );
123
 
 
124
 
        QFile dFile( fileUrl );
125
 
        if ( !dFile.exists() )
126
 
                return;
127
 
 
128
 
        if ( !dFile.open( QFile::ReadOnly ) )
129
 
                return;
130
 
 
131
 
        QString entry = QString( dFile.readAll() );
132
 
        dFile.close();
133
 
 
134
 
        __name = findIn( rxName, entry );
135
 
 
136
 
        if ( __name.isEmpty() )
137
 
                qDebug() << "Nameless monster:" << fileUrl;
138
 
 
139
 
        __type = findIn( rxType, entry );
140
 
        __exec = findIn( rxExec, entry );
141
 
 
142
 
        __icon = findIn( rxIcon, entry );
143
 
        __workPath = findIn( rxPath, entry );
144
 
        __mimeTypes = findIn( rxMime, entry ).split( ";", QString::SkipEmptyParts );
145
 
        QString __terminal = findIn( rxTerm, entry );
146
 
        __terminalMode = ( __terminal.toLower() == "true" ? true : false );
147
 
 
148
 
        __categories << findIn( rxCate, entry ).split( ";", QString::SkipEmptyParts );
149
 
        __comment = findIn( rxComm, entry );
150
 
 
151
 
        // By default set @v __multipleFiles to false
152
 
        __multipleFiles = false;
153
 
        __takesArgs = false;
154
 
 
155
 
        QStringList args = __exec.split( " " );
156
 
        foreach( QString arg, args ) {
157
 
                if ( arg == "%f" or arg == "%u" ) {
158
 
                        __multipleFiles = false;
159
 
                        __takesArgs = true;
160
 
                        __execArgs << "<#NEWBREEZE-ARG-FILE#>";
161
 
                }
162
 
 
163
 
                else if ( arg == "%F" or arg == "%U" ) {
164
 
                        __multipleFiles = true;
165
 
                        __takesArgs = true;
166
 
                        __execArgs << "<#NEWBREEZE-ARG-FILES#>";
167
 
                }
168
 
 
169
 
                else if ( arg == "%i" ) {
170
 
                        if ( !__icon.isEmpty() )
171
 
                                __execArgs << "--icon" << __icon;
172
 
                }
173
 
 
174
 
                else if ( arg == "%c" )
175
 
                        __execArgs << __name;
176
 
 
177
 
                else if ( arg == "%k" )
178
 
                        __execArgs << QUrl( fileUrl ).toLocalFile();
179
 
 
180
 
                else
181
 
                        __execArgs << arg;
182
 
        }
183
 
};