source: src-qt4/pc-controlpanel/deinfo.cpp @ 1620346

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 2 years ago

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**************************************************************************
2*   Copyright (C) 2011 by Yuri Momotyuk                                   *
3*   yurkis@gmail.com                                                      *
4*                                                                         *
5*   Permission is hereby granted, free of charge, to any person obtaining *
6*   a copy of this software and associated documentation files (the       *
7*   "Software"), to deal in the Software without restriction, including   *
8*   without limitation the rights to use, copy, modify, merge, publish,   *
9*   distribute, sublicense, and/or sell copies of the Software, and to    *
10*   permit persons to whom the Software is furnished to do so, subject to *
11*   the following conditions:                                             *
12*                                                                         *
13*   The above copyright notice and this permission notice shall be        *
14*   included in all copies or substantial portions of the Software.       *
15*                                                                         *
16*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
17*   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
18*   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
19*   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
20*   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
21*   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
22*   OTHER DEALINGS IN THE SOFTWARE.                                       *
23***************************************************************************/
24
25#include "deinfo.h"
26#include <QProcess>
27#include <QStringList>
28
29static const char* const DE_NAME = "DE name:";
30static const char* const DE_ACTIVE = "Current DE:";
31static const char* const DE_XDG = "XDG compatible:";
32static const char* const DE_INSTALLED = "Installed:";
33static const char* const DE_SUDO = "Sudo command:";
34
35///////////////////////////////////////////////////////////////////////////////
36#define TRY_GET_VALUE_STR(val_name, field)\
37if (Str.contains(val_name)){\
38                            Entry.field = Str.replace(val_name,"").trimmed();\
39                                          continue;}\
40
41#define TRY_GET_VALUE_BOOL(val_name, field, true_val)\
42if (Str.contains(val_name)){\
43                            Entry.field = Str.replace(val_name,"").trimmed().toLower() == QString(true_val).toLower();\
44                                          continue;}\
45
46int CDEList::refresh(bool isAll)
47{
48    mvDE.clear();
49
50    QStringList flags;
51    if (isAll)
52        flags<<"-a";
53    else
54        flags<<"-i";
55
56    QProcess* deinfo = new QProcess();
57    deinfo->setProcessChannelMode(QProcess::MergedChannels);
58    deinfo->start(QString("/usr/local/bin/de-info"), flags);
59    deinfo->waitForFinished(-1);
60    CDEInfo Entry;
61    QString Str;
62
63    while ( deinfo->canReadLine() )
64    {
65        Str = deinfo->readLine().simplified();
66        if (Str.contains(DE_NAME))
67        {
68            if (Entry.mName.length())
69            {
70                mvDE.push_back(Entry);
71                Entry = CDEInfo();
72            }
73            Entry.mName = Str.replace(DE_NAME,"").trimmed();
74            continue;
75        }//if found 'DE name'
76
77        TRY_GET_VALUE_BOOL(DE_ACTIVE, misActive, "yes");
78        TRY_GET_VALUE_BOOL(DE_INSTALLED, misInstalled, "yes");
79        TRY_GET_VALUE_STR(DE_SUDO, mSudoCommand);
80    }//while process output reading
81
82    if (Entry.mName.length())
83        mvDE.push_back(Entry);
84
85    return mvDE.size();
86}
87
88///////////////////////////////////////////////////////////////////////////////
89CDEInfo* CDEList::active()
90{
91    for(int i =0; i<mvDE.size(); i++)
92    {
93        if (mvDE[i].misActive)
94            return &mvDE[i];
95    }
96    return NULL;
97}
98
99///////////////////////////////////////////////////////////////////////////////
100CDEInfo* CDEList::byName(QString Name)
101{
102    for (int i =0; i<mvDE.size(); i++)
103    {
104        if (!mvDE[i].mName.compare(Name.trimmed(), Qt::CaseInsensitive))
105            return &mvDE[i];
106    }
107    return NULL;
108}
109
110///////////////////////////////////////////////////////////////////////////////
111CSingleDEList& CSingleDEList::getRef()
112{
113    static CSingleDEList instance;
114    return instance;
115}
Note: See TracBrowser for help on using the repository browser.