summaryrefslogtreecommitdiffstats
path: root/tderadio3/src/widgetplugins.cpp
blob: 462030e7bd5b63156328b03e527b3d0606f595e1 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/***************************************************************************
                          widgetplugins.cpp  -  description
                             -------------------
    begin                : Mi Aug 27 2003
    copyright            : (C) 2003 by Martin Witte
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "include/widgetplugins.h"
#include "include/pluginmanager.h"

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <twin.h>
#include <tqwidget.h>
#include <tdeconfig.h>
#include <tdelocale.h>

WidgetPluginBase::WidgetPluginBase(const TQString &name, const TQString &description)
  : PluginBase(name, description),
    m_geoCacheValid(false),
    m_geoRestoreFlag(false),
    m_restoreShow(false)
{
}

/*
TQWidget *WidgetPluginBase::getWidget()
{
    return dynamic_cast<TQWidget*>(this);
}


const TQWidget *WidgetPluginBase::getWidget() const
{
    return dynamic_cast<const TQWidget*>(this);
}
*/

void WidgetPluginBase::notifyManager(bool shown)
{
    if (m_manager)
        m_manager->noticeWidgetPluginShown(this, shown);
}


bool WidgetPluginBase::isReallyVisible(const TQWidget *_w) const
{
    const TQWidget *w = _w ? _w : getWidget();
    if (!w) return false;
    KWin::WindowInfo i = KWin::WindowInfo(w->winId(), 0, 0);
    return (i.mappingState() == NET::Visible)
            && w->isVisible()
            && (i.onAllDesktops() || i.isOnCurrentDesktop());
}


bool WidgetPluginBase::isAnywhereVisible(const TQWidget *_w) const
{
    const TQWidget *w = _w ? _w : getWidget();
    if (!w) return false;
    return w->isVisible();
}


void WidgetPluginBase::pShow(bool on)
{
    TQWidget *w = getWidget();
    if (!w) return;
    if (on && !isReallyVisible(w))
        w->show();
    else if (!on && !w->isHidden())
        w->hide();
}


void WidgetPluginBase::pToggleShown()
{
    TQWidget *w = getWidget();
    if (!w) return;
    if (!isReallyVisible(w))
        w->show();
    else
        w->hide();
}


void WidgetPluginBase::pShowOnOrgDesktop()
{
    KWin::setMainWindow(getWidget(), 0);

    logDebug(TQString("%1::pShowOnOrgDesktop: all: %2, desktop: %3, visible:%4, anywherevisible:%5, cachevalid: %6").arg(name()).arg(m_saveSticky).arg(m_saveDesktop).arg(isReallyVisible()).arg(isAnywhereVisible()).arg(m_geoCacheValid));
    if (m_geoCacheValid && (!isReallyVisible() || m_geoRestoreFlag) ) {
        TQWidget *w = getWidget();
        if (!w) return;
        WId  id = w->winId();

        KWin::setOnAllDesktops(id, m_saveSticky);
        if (!m_saveSticky) {
            KWin::setOnDesktop(id, m_saveDesktop);
        }

        w->resize(m_saveGeometry.size());
        w->move(m_saveGeometry.topLeft());

        if (m_saveMinimized) {
            w->showMinimized();
            KWin::iconifyWindow(id);
        } else if (m_saveMaximized) {
            w->showMaximized();
        } else {
            w->showNormal();
            KWin::deIconifyWindow(id);
        }

    }
}

void WidgetPluginBase::pShow()
{
    KWin::setMainWindow(getWidget(), 0);

    logDebug(TQString("%1::pShow: all: %2, desktop: %3, visible:%4, anywherevisible:%5, cachevalid: %6").arg(name()).arg(m_saveSticky).arg(m_saveDesktop).arg(isReallyVisible()).arg(isAnywhereVisible()).arg(m_geoCacheValid));
    if (m_geoCacheValid && (!isReallyVisible() || m_geoRestoreFlag) ) {
        TQWidget *w = getWidget();
        if (!w) return;
        WId  id = w->winId();

        KWin::setOnAllDesktops(id, m_saveSticky);
        if (!m_saveSticky)
            KWin::setOnDesktop(id, KWin::currentDesktop());

        w->resize(m_saveGeometry.size());
        w->move(m_saveGeometry.topLeft());
        KWin::deIconifyWindow(id);
    }
}


void WidgetPluginBase::pHide()
{
    logDebug(TQString("%1::pHide1: all: %2, desktop: %3, visible:%4, anywherevisible:%5, cachevalid: %6").arg(name()).arg(m_saveSticky).arg(m_saveDesktop).arg(isReallyVisible()).arg(isAnywhereVisible()).arg(m_geoCacheValid));
    getKWinState();
    logDebug(TQString("%1::pHide2: all: %2, desktop: %3, visible:%4, anywherevisible:%5, cachevalid: %6").arg(name()).arg(m_saveSticky).arg(m_saveDesktop).arg(isReallyVisible()).arg(isAnywhereVisible()).arg(m_geoCacheValid));
}


void WidgetPluginBase::pShowEvent(TQShowEvent *)
{
    notifyManager (true);
}


void WidgetPluginBase::pHideEvent(TQHideEvent *)
{
    notifyManager (false);
}


void WidgetPluginBase::getKWinState(const TQWidget *_w) const
{
    if (m_geoRestoreFlag) return;

    const TQWidget *w = _w ? _w : getWidget();
    if (!w) return;
    if (w->isVisible()) {
        KWin::WindowInfo i = KWin::WindowInfo(w->winId(), 0, 0);
        m_saveMinimized    = i.isMinimized();
        m_saveMaximized    = w->isMaximized();
        m_saveSticky       = i.onAllDesktops();
        m_saveDesktop      = i.desktop();
        m_saveGeometry     = TQRect(w->pos(), w->size());
        m_geoCacheValid    = true;
    }
}


void   WidgetPluginBase::saveState (TDEConfig *config) const
{
    const TQWidget *w = getWidget();
    getKWinState(w);

    config->writeEntry("hidden",   w ? w->isHidden() : false);
    config->writeEntry("minimized",  m_saveMinimized);
    config->writeEntry("maximized",  m_saveMaximized);
    config->writeEntry("sticky",     m_saveSticky);
    config->writeEntry("desktop",    m_saveDesktop);
    config->writeEntry("geometry",   m_saveGeometry);
    config->writeEntry("geoCacheValid", m_geoCacheValid);
}


void   WidgetPluginBase::restoreState (TDEConfig *config, bool showByDefault)
{
    m_geoCacheValid = config->readBoolEntry("geoCacheValid", false);
    m_saveDesktop   = config->readNumEntry ("desktop",        1);
    m_saveSticky    = config->readBoolEntry("sticky",     false);
    m_saveMaximized = config->readBoolEntry("maximized",  false);
    m_saveMinimized = config->readBoolEntry("minimized",  false);
    m_saveGeometry  = config->readRectEntry("geometry");

    m_restoreShow  = !config->readBoolEntry("hidden", !showByDefault);
}


void   WidgetPluginBase::restoreState (TDEConfig *config)
{
    restoreState(config, true);
}


void   WidgetPluginBase::startPlugin()
{
    PluginBase::startPlugin();

    TQWidget *w = getWidget();
    if (w) {
        m_geoRestoreFlag = true;
        if (!m_restoreShow) w->hide();
        else                w->show();
        m_geoRestoreFlag = false;
    }
}