~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/randr/krandrmodule.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2007      Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
 
3
 * Copyright (c) 2002,2003 Hamish Rodda <rodda@kde.org>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "krandrmodule.h"
 
21
#include "legacyrandrconfig.h"
 
22
#include <QTextStream>
 
23
#include "legacyrandrscreen.h"
 
24
#include "randrdisplay.h"
 
25
#include "randrconfig.h"
 
26
 
 
27
#include <KPluginFactory>
 
28
#include <KPluginLoader>
 
29
#include <KDebug>
 
30
#include <config-randr.h>
 
31
 
 
32
#include "randr.h"
 
33
 
 
34
// DLL Interface for kcontrol
 
35
K_PLUGIN_FACTORY(KSSFactory, registerPlugin<KRandRModule>();)
 
36
K_EXPORT_PLUGIN(KSSFactory("krandr"))
 
37
 
 
38
KRandRModule::KRandRModule(QWidget *parent, const QVariantList&)
 
39
    : KCModule(KSSFactory::componentData(), parent)
 
40
{
 
41
        m_display = new RandRDisplay();
 
42
        if (!m_display->isValid())
 
43
        {
 
44
                QVBoxLayout *topLayout = new QVBoxLayout(this);
 
45
                QLabel *label =
 
46
                    new QLabel(i18n("Your X server does not support resizing and "
 
47
                                    "rotating the display. Please update to version 4.3 "
 
48
                                                "or greater. You need the X Resize, Rotate, and Reflect "
 
49
                                                "extension (RANDR) version 1.1 or greater to use this "
 
50
                                                "feature."), this);
 
51
                                                
 
52
                label->setWordWrap(true);
 
53
                topLayout->addWidget(label);
 
54
                kWarning() << "Error: " << m_display->errorCode() ;
 
55
                return;
 
56
        }
 
57
 
 
58
        QVBoxLayout* topLayout = new QVBoxLayout(this);
 
59
        topLayout->setMargin(0);
 
60
        topLayout->setSpacing(KDialog::spacingHint());
 
61
 
 
62
#ifdef HAS_RANDR_1_2
 
63
        if (RandR::has_1_2)
 
64
        {
 
65
                m_config = new RandRConfig(this, m_display);
 
66
                connect(m_config, SIGNAL(changed(bool)), SIGNAL(changed(bool)));
 
67
                topLayout->addWidget(m_config);
 
68
        }
 
69
        else
 
70
#endif
 
71
        {
 
72
                m_legacyConfig = new LegacyRandRConfig(this, m_display);
 
73
                connect(m_legacyConfig, SIGNAL(changed(bool)), SIGNAL(changed(bool)));
 
74
                topLayout->addWidget(m_legacyConfig);
 
75
        }
 
76
 
 
77
        //topLayout->addStretch(1);
 
78
 
 
79
        setButtons(KCModule::Apply);
 
80
}
 
81
 
 
82
KRandRModule::~KRandRModule(void)
 
83
{
 
84
        delete m_display;
 
85
}
 
86
 
 
87
void KRandRModule::defaults()
 
88
{
 
89
        if (!m_display->isValid()) {
 
90
                return;
 
91
        }
 
92
#ifdef HAS_RANDR_1_2
 
93
        if (RandR::has_1_2)
 
94
                m_config->defaults();
 
95
        else
 
96
#endif
 
97
                m_legacyConfig->defaults();
 
98
}
 
99
 
 
100
void KRandRModule::load()
 
101
{
 
102
        kDebug() << "Loading KRandRModule...";
 
103
        
 
104
        if (!m_display->isValid()) {
 
105
                return;
 
106
        }
 
107
#ifdef HAS_RANDR_1_2
 
108
        if (RandR::has_1_2)
 
109
                m_config->load();
 
110
        else
 
111
#endif
 
112
                m_legacyConfig->load();
 
113
 
 
114
        emit changed(false);
 
115
}
 
116
 
 
117
void KRandRModule::save()
 
118
{
 
119
        if (!m_display->isValid()) {
 
120
                return;
 
121
        }
 
122
#ifdef HAS_RANDR_1_2
 
123
        if (RandR::has_1_2)
 
124
                m_config->save();
 
125
        else
 
126
#endif
 
127
                m_legacyConfig->save();
 
128
 
 
129
}
 
130
 
 
131
void KRandRModule::apply()
 
132
{
 
133
        if (!m_display->isValid()) {
 
134
                return;
 
135
        }
 
136
#ifdef HAS_RANDR_1_2
 
137
        if (RandR::has_1_2)
 
138
                m_config->apply();
 
139
        else
 
140
#endif
 
141
                m_legacyConfig->apply();
 
142
}
 
143
 
 
144
 
 
145
#include "krandrmodule.moc"