File: kaboutapplicationdialog.cpp

package info (click to toggle)
kde4libs 4%3A4.8.4-4%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,588 kB
  • sloc: cpp: 746,914; xml: 8,370; ansic: 6,295; java: 4,060; perl: 2,930; yacc: 2,462; sh: 1,225; python: 1,081; ruby: 337; lex: 278; makefile: 29
file content (339 lines) | stat: -rw-r--r-- 14,507 bytes parent folder | download
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/* This file is part of the KDE libraries
   Copyright (C) 2007 Urs Wolfer <uwolfer at kde.org>
   Copyright (C) 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
   Copyright (C) 2010 Teo Mrnjavac <teo@kde.org>

   Parts of this class have been take from the KAboutApplication class, which was
   Copyright (C) 2000 Waldo Bastian (bastian@kde.org) and Espen Sand (espen@kde.org)

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "kaboutapplicationdialog.h"

#include "kaboutapplicationpersonmodel_p.h"
#include "kaboutapplicationpersonlistview_p.h"
#include "kaboutapplicationpersonlistdelegate_p.h"
#include "kdeui/icons/kiconloader.h"
#include "kdeui/kernel/kapplication.h"
#include "kdeui/kernel/kglobalsettings.h"
#include "kdeui/widgets/ktextbrowser.h"
#include "kdeui/widgets/ktitlewidget.h"

#include <kdecore/kernel/kaboutdata.h>
#include <kdecore/kernel/kglobal.h>
#include <kdecore/localization/klocale.h>

#include <QtGui/QLabel>
#include <QtGui/QLayout>
#include <QtGui/QPushButton>
#include <QtGui/QScrollBar>
#include <QtGui/QTabWidget>

class KAboutApplicationDialog::Private
{
public:
    Private(KAboutApplicationDialog *parent)
        : q(parent),
          aboutData(0)
    {}

    void init( const KAboutData *aboutData, Options opt );

    void _k_showLicense( const QString &number );

    KAboutApplicationDialog *q;

    const KAboutData *aboutData;
};

KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, QWidget *parent)
  : KDialog(parent),
    d(new Private(this))
{
    d->init( aboutData, NoOptions );
}

KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, Options opt, QWidget *parent)
  : KDialog(parent),
    d(new Private(this))
{
    d->init( aboutData, opt );
}

void KAboutApplicationDialog::Private::init( const KAboutData *ad, Options opt )
{
    if (ad == 0)
        ad = KGlobal::mainComponent().aboutData();

    aboutData = ad;

    if (!aboutData) {
        QLabel *errorLabel = new QLabel(i18n("<qt>No information available.<br />"
                                             "The supplied KAboutData object does not exist.</qt>"), q);

        errorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
        q->setMainWidget(errorLabel);
        return;
    }

    q->setPlainCaption(i18n("About %1", aboutData->programName()));
    q->setButtons(KDialog::Close);
    q->setDefaultButton(KDialog::Close);
    q->setModal(false);

    //Set up the title widget...
    KTitleWidget *titleWidget = new KTitleWidget(q);

    QIcon windowIcon;
    if (!aboutData->programIconName().isEmpty()) {
        windowIcon = KIcon(aboutData->programIconName());
    } else {
        windowIcon = qApp->windowIcon();
    }
    titleWidget->setPixmap(windowIcon.pixmap(64, 64), KTitleWidget::ImageLeft);
    if (aboutData->programLogo().canConvert<QPixmap>())
        titleWidget->setPixmap(aboutData->programLogo().value<QPixmap>(), KTitleWidget::ImageLeft);
    else if (aboutData->programLogo().canConvert<QImage>())
        titleWidget->setPixmap(QPixmap::fromImage(aboutData->programLogo().value<QImage>()), KTitleWidget::ImageLeft);

    if ( opt & HideKdeVersion )
        titleWidget->setText(i18n("<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />&nbsp;</html>",
                                  aboutData->programName(), aboutData->version()));
    else
        titleWidget->setText(i18nc("Program name, version and KDE platform version; do not translate 'Development Platform'",
                                   "<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />Using KDE Development Platform %3</html>",
                                   aboutData->programName(), aboutData->version(), QString(KDE_VERSION_STRING)));

    //Then the tab bar...
    QTabWidget *tabWidget = new QTabWidget;
    tabWidget->setUsesScrollButtons(false);

    //Set up the first page...
    QString aboutPageText = aboutData->shortDescription() + '\n';

    if (!aboutData->otherText().isEmpty())
        aboutPageText += '\n' + aboutData->otherText() + '\n';

    if (!aboutData->copyrightStatement().isEmpty())
        aboutPageText += '\n' + aboutData->copyrightStatement() + '\n';

    if (!aboutData->homepage().isEmpty())
        aboutPageText += '\n' + QString("<a href=\"%1\">%1</a>").arg(aboutData->homepage()) + '\n';
    aboutPageText = aboutPageText.trimmed();

    QLabel *aboutLabel = new QLabel;
    aboutLabel->setWordWrap(true);
    aboutLabel->setOpenExternalLinks(true);
    aboutLabel->setText(aboutPageText.replace('\n', "<br />"));
    aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);

    QVBoxLayout *aboutLayout = new QVBoxLayout;
    aboutLayout->addStretch();
    aboutLayout->addWidget(aboutLabel);

    const int licenseCount = aboutData->licenses().count();
    for (int i = 0; i < licenseCount; ++i) {
        const KAboutLicense &license = aboutData->licenses().at(i);

        QLabel *showLicenseLabel = new QLabel;
        showLicenseLabel->setText(QString("<a href=\"%1\">%2</a>").arg(QString::number(i),
                                                                       i18n("License: %1",
                                                                            license.name(KAboutData::FullName))));
        showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
        connect(showLicenseLabel, SIGNAL(linkActivated(QString)), q, SLOT(_k_showLicense(QString)));

        aboutLayout->addWidget(showLicenseLabel);
    }

    aboutLayout->addStretch();

    QWidget *aboutWidget = new QWidget(q);
    aboutWidget->setLayout(aboutLayout);

    tabWidget->addTab(aboutWidget, i18n("&About"));

    //Palette needed at least for translators...
    QPalette transparentBackgroundPalette;
    transparentBackgroundPalette.setColor(QPalette::Base, Qt::transparent);
    transparentBackgroundPalette.setColor(QPalette::Text, transparentBackgroundPalette.color(QPalette::WindowText));

    //And here we go, authors page...
    const int authorCount = aboutData->authors().count();
    if (authorCount) {
        QWidget *authorWidget = new QWidget( q );
        QVBoxLayout *authorLayout = new QVBoxLayout( authorWidget );
        authorLayout->setMargin( 0 );

        if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) {
            QLabel *bugsLabel = new QLabel( authorWidget );
            bugsLabel->setContentsMargins( 4, 2, 0, 4 );
            bugsLabel->setOpenExternalLinks( true );
            if (!aboutData->customAuthorTextEnabled()) {
                if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == "submit@bugs.kde.org")
                    bugsLabel->setText( i18n("Please use <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a> to report bugs.\n") );
                else {
                    if( ( aboutData->authors().count() == 1 ) &&
                        ( aboutData->authors().first().emailAddress() == aboutData->bugAddress() ) ) {
                        bugsLabel->setText( i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
                                              aboutData->authors().first().emailAddress(),
                                              aboutData->authors().first().emailAddress() ) );
                    }
                    else {
                        bugsLabel->setText( i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
                                              aboutData->bugAddress(), aboutData->bugAddress()));
                    }
                }
            }
            else
                bugsLabel->setText( aboutData->customAuthorRichText() );
            bugsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
            authorLayout->addWidget( bugsLabel );
        }

        KDEPrivate::KAboutApplicationPersonModel *authorModel =
                new KDEPrivate::KAboutApplicationPersonModel( aboutData->authors(),
                                                              aboutData->ocsProviderUrl(),
                                                              authorWidget );

        KDEPrivate::KAboutApplicationPersonListView *authorView =
                new KDEPrivate::KAboutApplicationPersonListView( authorWidget );

        KDEPrivate::KAboutApplicationPersonListDelegate *authorDelegate =
                new KDEPrivate::KAboutApplicationPersonListDelegate( authorView, authorView );

        authorView->setModel( authorModel );
        authorView->setItemDelegate( authorDelegate );
        authorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
        authorLayout->addWidget( authorView );

        QString authorPageTitle = QString( ( authorCount == 1 ) ? i18n("A&uthor") : i18n("A&uthors") );
        tabWidget->addTab( authorWidget, authorPageTitle );
    }

    //And credits page...
    const int creditsCount = aboutData->credits().count();
    if (creditsCount) {
        QWidget *creditWidget = new QWidget( q );
        QVBoxLayout *creditLayout = new QVBoxLayout( creditWidget );
        creditLayout->setMargin( 0 );

        KDEPrivate::KAboutApplicationPersonModel *creditModel =
                new KDEPrivate::KAboutApplicationPersonModel( aboutData->credits(),
                                                              aboutData->ocsProviderUrl(),
                                                              creditWidget );

        KDEPrivate::KAboutApplicationPersonListView *creditView =
                new KDEPrivate::KAboutApplicationPersonListView( creditWidget );

        KDEPrivate::KAboutApplicationPersonListDelegate *creditDelegate =
                new KDEPrivate::KAboutApplicationPersonListDelegate( creditView, creditView );

        creditView->setModel( creditModel );
        creditView->setItemDelegate( creditDelegate );
        creditView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
        creditLayout->addWidget( creditView );

        tabWidget->addTab( creditWidget, i18n("&Thanks To"));
    }

    //Finally, the optional translators page...
    if ( !( opt & HideTranslators ) ) {
        const int translatorsCount = aboutData->translators().count();
        if( translatorsCount ) {
            QWidget *translatorWidget = new QWidget( q );
            QVBoxLayout *translatorLayout = new QVBoxLayout( translatorWidget );
            translatorLayout->setMargin( 0 );

            KDEPrivate::KAboutApplicationPersonModel *translatorModel =
                    new KDEPrivate::KAboutApplicationPersonModel( aboutData->translators(),
                                                                  aboutData->ocsProviderUrl(),
                                                                  translatorWidget );

            KDEPrivate::KAboutApplicationPersonListView *translatorView =
                    new KDEPrivate::KAboutApplicationPersonListView( translatorWidget );

            KDEPrivate::KAboutApplicationPersonListDelegate *translatorDelegate =
                    new KDEPrivate::KAboutApplicationPersonListDelegate( translatorView, translatorView );

            translatorView->setModel( translatorModel );
            translatorView->setItemDelegate( translatorDelegate );
            translatorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
            translatorLayout->addWidget( translatorView );

            QString aboutTranslationTeam = KAboutData::aboutTranslationTeam();
            if( !aboutTranslationTeam.isEmpty() ) {
                QLabel *translationTeamLabel = new QLabel( translatorWidget );
                translationTeamLabel->setContentsMargins( 4, 2, 4, 4 );
                translationTeamLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
                translationTeamLabel->setWordWrap( true );
                translationTeamLabel->setText( aboutTranslationTeam );
                translatorLayout->addWidget( translationTeamLabel );
                //TODO: this could be displayed as a view item to save space
            }

            tabWidget->addTab( translatorWidget, i18n("T&ranslation"));
        }
    }

    //And we jam everything together in a layout...
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(titleWidget);
    mainLayout->addWidget(tabWidget);
    mainLayout->setMargin(0);

    QWidget *mainWidget = new QWidget;
    mainWidget->setLayout(mainLayout);

    q->setMainWidget(mainWidget);
}

KAboutApplicationDialog::~KAboutApplicationDialog()
{
    delete d;
}

void KAboutApplicationDialog::Private::_k_showLicense( const QString &number )
{
    KDialog *dialog = new KDialog(q);

    dialog->setCaption(i18n("License Agreement"));
    dialog->setButtons(KDialog::Close);
    dialog->setDefaultButton(KDialog::Close);

    const QFont font = KGlobalSettings::fixedFont();
    QFontMetrics metrics(font);

    const QString licenseText = aboutData->licenses().at(number.toInt()).text();
    KTextBrowser *licenseBrowser = new KTextBrowser;
    licenseBrowser->setFont(font);
    licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
    licenseBrowser->setText(licenseText);

    dialog->setMainWidget(licenseBrowser);

    // try to set up the dialog such that the full width of the
    // document is visible without horizontal scroll-bars being required
    const qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint())
        + licenseBrowser->verticalScrollBar()->width() * 2;

    // try to allow enough height for a reasonable number of lines to be shown
    const int idealHeight = metrics.height() * 30;

    dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight)));
    dialog->show();
}

#include "kaboutapplicationdialog.moc"