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

releng/10.0.1releng/10.0.2
Last change on this file since 11d9290 was 11d9290, checked in by Ken Moore <ken@…>, 6 months ago

Enable a bit of debugging within the control panel.

  • 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        //qDebug() << "de-info line:" << Str;
67        if (Str.contains(DE_NAME))
68        {
69            if (Entry.mName.length())
70            {
71                mvDE.push_back(Entry);
72                Entry = CDEInfo();
73            }
74            Entry.mName = Str.replace(DE_NAME,"").trimmed();
75            continue;
76        }//if found 'DE name'
77
78        TRY_GET_VALUE_BOOL(DE_ACTIVE, misActive, "yes");
79        TRY_GET_VALUE_BOOL(DE_INSTALLED, misInstalled, "yes");
80        TRY_GET_VALUE_STR(DE_SUDO, mSudoCommand);
81    }//while process output reading
82
83    if (Entry.mName.length())
84        mvDE.push_back(Entry);
85
86    return mvDE.size();
87}
88
89///////////////////////////////////////////////////////////////////////////////
90CDEInfo* CDEList::active()
91{
92    for(int i =0; i<mvDE.size(); i++)
93    {
94        if (mvDE[i].misActive)
95            return &mvDE[i];
96    }
97    return NULL;
98}
99
100///////////////////////////////////////////////////////////////////////////////
101CDEInfo* CDEList::byName(QString Name)
102{
103    for (int i =0; i<mvDE.size(); i++)
104    {
105        if (!mvDE[i].mName.compare(Name.trimmed(), Qt::CaseInsensitive))
106            return &mvDE[i];
107    }
108    return NULL;
109}
110
111///////////////////////////////////////////////////////////////////////////////
112CSingleDEList& CSingleDEList::getRef()
113{
114    static CSingleDEList instance;
115    return instance;
116}
Note: See TracBrowser for help on using the repository browser.