summaryrefslogtreecommitdiffstats
path: root/opensuse/core/qt3/qtkdeintegration_x11.cpp
blob: 8f837b41242bd38994b0ceaef068ceac58929ac4 (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
236
237
238
239
240
241
242
#define QT_CLEAN_NAMESPACE
#include "qtkdeintegration_x11_p.h"

#include <qcolordialog.h>
#include <qfiledialog.h>
#include <qfontdialog.h>
#include <qlibrary.h>
#include <qregexp.h>
#include <qmessagebox.h>
#include <stdlib.h>

bool QKDEIntegration::inited = false;
bool QKDEIntegration::enable = false;

bool QKDEIntegration::enabled()
    {
    if( !inited )
        initLibrary();
    return enable;
    }

static QCString findLibrary()
    {
    if( getenv( "QT_NO_KDE_INTEGRATION" ) == NULL
        || getenv( "QT_NO_KDE_INTEGRATION" )[ 0 ] == '0' )
        {
#ifdef USE_LIB64_PATHES
        return "/opt/kde3/lib64/kde3/plugins/integration/libqtkde";
#else
        return "/opt/kde3/lib/kde3/plugins/integration/libqtkde";
#endif
        }
    return "";
    }

inline static long widgetToWinId( const QWidget* w )
    {
    return w != NULL ? w->winId() : 0;
    }

inline static QFont fontPtrToFontRef( const QFont* f )
    {
    return f != NULL ? *f : QFont();
    }

// ---
static bool (*qtkde_initializeIntegration)( );
static QStringList (*qtkde_getOpenFileNames)( const QString& filter, QString* workingDirectory,
    long parent, const QCString& name, const QString& caption, QString* selectedFilter,
    bool multiple );
static QString (*qtkde_getSaveFileName)( const QString& initialSelection, const QString& filter,
    QString* workingDirectory, long parent, const QCString& name, const QString& caption,
    QString* selectedFilter );
static QString (*qtkde_getExistingDirectory)( const QString& initialDirectory, long parent,
    const QCString& name, const QString& caption );
static QColor (*qtkde_getColor)( const QColor& color, long parent, const QCString& name );
static QFont (*qtkde_getFont)( bool* ok, const QFont& def, long parent, const QCString& name );
static int (*qtkde_messageBox1)( int type, long parent, const QString& caption, const QString& text,
    int button0, int button1, int button2 );
static int (*qtkde_messageBox2)( int type, long parent, const QString& caption, const QString& text,
    const QString& button0Text, const QString& button1Text, const QString& button2Text,
    int defaultButton, int escapeButton );

void QKDEIntegration::initLibrary()
    {
    if( !inited )
        {
        enable = false;
        inited = true;
        QString libpath = findLibrary();
        if( libpath.isEmpty())
            return;
        QLibrary lib( libpath );
        lib.setAutoUnload( false );
        qtkde_initializeIntegration = (
            bool (*)( )
            )
            lib.resolve("initializeIntegration");
        if( qtkde_initializeIntegration == NULL )
            return;
        qtkde_getOpenFileNames = (
            QStringList (*)( const QString& filter, QString* workingDirectory, long parent,
                const QCString& name, const QString& caption, QString* selectedFilter,
                bool multiple )
            )
            lib.resolve("getOpenFileNames");
        if( qtkde_getOpenFileNames == NULL )
            return;
        qtkde_getSaveFileName = (
            QString (*)( const QString& initialSelection, const QString& filter, QString* workingDirectory,
                long parent, const QCString& name, const QString& caption, QString* selectedFilter )
            )
            lib.resolve("getSaveFileName");
        if( qtkde_getSaveFileName == NULL )
            return;
        qtkde_getExistingDirectory = (
            QString (*)( const QString& initialDirectory, long parent, const QCString& name,
                const QString& caption )
            )
            lib.resolve("getExistingDirectory");
        if( qtkde_getExistingDirectory == NULL )
            return;
        qtkde_getColor = (
            QColor (*)( const QColor& color, long parent, const QCString& name )
            )
            lib.resolve("getColor");
        if( qtkde_getColor == NULL )
            return;
        qtkde_getFont = (
            QFont (*)( bool* ok, const QFont& def, long parent, const QCString& name )
            )
            lib.resolve("getFont");
        if( qtkde_getFont == NULL )
            return;
        qtkde_messageBox1 = (
            int (*)( int type, long parent, const QString& caption, const QString& text,
                int button0, int button1, int button2 )
            )
            lib.resolve("messageBox1");
        if( qtkde_messageBox1 == NULL )
            return;
        qtkde_messageBox2 = (
            int (*)( int type, long parent, const QString& caption, const QString& text,
                const QString& button0Text, const QString& button1Text, const QString& button2Text,
                int defaultButton, int escapeButton )
            )
            lib.resolve("messageBox2");
        if( qtkde_messageBox2 == NULL )
            return;
        enable = qtkde_initializeIntegration();
        }
    }

bool QKDEIntegration::initializeIntegration( )
    {
    return qtkde_initializeIntegration(
         );
    }
QStringList QKDEIntegration::getOpenFileNames( const QString& filter, QString* workingDirectory,
    QWidget* parent, const char* name, const QString& caption, QString* selectedFilter,
    bool multiple )
    {
    return qtkde_getOpenFileNames(
        filter, workingDirectory, widgetToWinId( parent ), name, caption, selectedFilter, multiple );
    }
QString QKDEIntegration::getSaveFileName( const QString& initialSelection, const QString& filter,
    QString* workingDirectory, QWidget* parent, const char* name, const QString& caption,
    QString* selectedFilter )
    {
    return qtkde_getSaveFileName(
        initialSelection, filter, workingDirectory, widgetToWinId( parent ), name, caption, selectedFilter );
    }
QString QKDEIntegration::getExistingDirectory( const QString& initialDirectory, QWidget* parent,
    const char* name, const QString& caption )
    {
    return qtkde_getExistingDirectory(
        initialDirectory, widgetToWinId( parent ), name, caption );
    }
QColor QKDEIntegration::getColor( const QColor& color, QWidget* parent, const char* name )
    {
    return qtkde_getColor(
        color, widgetToWinId( parent ), name );
    }
QFont QKDEIntegration::getFont( bool* ok, const QFont* def, QWidget* parent, const char* name )
    {
    return qtkde_getFont(
        ok, fontPtrToFontRef( def ), widgetToWinId( parent ), name );
    }
int QKDEIntegration::messageBox1( int type, QWidget* parent, const QString& caption,
    const QString& text, int button0, int button1, int button2 )
    {
    return qtkde_messageBox1(
        type, widgetToWinId( parent ), caption, text, button0, button1, button2 );
    }
int QKDEIntegration::messageBox2( int type, QWidget* parent, const QString& caption,
    const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text,
    int defaultButton, int escapeButton )
    {
    return qtkde_messageBox2(
        type, widgetToWinId( parent ), caption, text, button0Text, button1Text, button2Text, defaultButton, escapeButton );
    }
// ---

int QKDEIntegration::information( QWidget* parent, const QString& caption,
    const QString& text, int button0, int button1, int button2 )
    {
    return qtkde_messageBox1(
        QMessageBox::Information, widgetToWinId( parent ), caption, text, button0, button1, button2 );
    }

int QKDEIntegration::question( QWidget* parent, const QString& caption,
    const QString& text, int button0, int button1, int button2 )
    {
    return qtkde_messageBox1(
        QMessageBox::Question, widgetToWinId( parent ), caption, text, button0, button1, button2 );
    }

int QKDEIntegration::warning( QWidget* parent, const QString& caption,
    const QString& text, int button0, int button1, int button2 )
    {
    return qtkde_messageBox1(
        QMessageBox::Warning, widgetToWinId( parent ), caption, text, button0, button1, button2 );
    }

int QKDEIntegration::critical( QWidget* parent, const QString& caption,
    const QString& text, int button0, int button1, int button2 )
    {
    return qtkde_messageBox1(
        QMessageBox::Critical, widgetToWinId( parent ), caption, text, button0, button1, button2 );
    }

int QKDEIntegration::information( QWidget* parent, const QString& caption,
    const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text,
    int defaultButton, int escapeButton )
    {
    return qtkde_messageBox2(
        QMessageBox::Information, widgetToWinId( parent ), caption, text, button0Text, button1Text, button2Text, defaultButton, escapeButton );
    }

int QKDEIntegration::question( QWidget* parent, const QString& caption,
    const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text,
    int defaultButton, int escapeButton )
    {
    return qtkde_messageBox2(
        QMessageBox::Question, widgetToWinId( parent ), caption, text, button0Text, button1Text, button2Text, defaultButton, escapeButton );
    }

int QKDEIntegration::warning( QWidget* parent, const QString& caption,
    const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text,
    int defaultButton, int escapeButton )
    {
    return qtkde_messageBox2(
        QMessageBox::Warning, widgetToWinId( parent ), caption, text, button0Text, button1Text, button2Text, defaultButton, escapeButton );
    }

int QKDEIntegration::critical( QWidget* parent, const QString& caption,
    const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text,
    int defaultButton, int escapeButton )
    {
    return qtkde_messageBox2(
        QMessageBox::Critical, widgetToWinId( parent ), caption, text, button0Text, button1Text, button2Text, defaultButton, escapeButton );
    }