kpartloader.cpp 3.54 KB
Newer Older
Luigi Toscano's avatar
Luigi Toscano committed
1
/*  This file is part of the KDE project
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *  Copyright 2008  David Faure  <faure@kde.org>
 *
 *  This library is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2 of the License or ( at
 *  your option ) version 3 or, at the discretion of KDE e.V. ( which shall
 *  act as a proxy as in section 14 of the GPLv3 ), any later version.
 *
 *  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 Lesser 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 "kpartloader.h"
Luigi Toscano's avatar
Luigi Toscano committed
22

23
24
// app
#include "kpartloader_version.h"
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
25
// KF
Luigi Toscano's avatar
Luigi Toscano committed
26
27
28
29
30
#include <KAboutData>
#include <KActionCollection>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KPluginLoader>
31
#include <KAboutApplicationDialog>
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
32
33
34
35
36
37
38
39
#include <KMessageBox>

// Qt
#include <QAction>
#include <QApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QIcon>
Laurent Montel's avatar
Laurent Montel committed
40

41
42

KPartLoaderWindow::KPartLoaderWindow(const QString& partLib)
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
43
    : m_part(nullptr)
44
{
Luigi Toscano's avatar
Luigi Toscano committed
45
    setXMLFile(QStringLiteral("kpartloaderui.rc"));
46

47
48
49
50
51
52
53
    QAction * a = new QAction( QIcon::fromTheme(QStringLiteral("application-exit")), i18n("&Quit"), this );
    actionCollection()->addAction( "file_quit", a );
    connect(a, SIGNAL(triggered()), this, SLOT(close()));

    a = actionCollection()->addAction(QStringLiteral("help_about_kpart"));
    a->setText(i18n("&About KPart..."));
    connect(a, SIGNAL(triggered()), this, SLOT(aboutKPart()));
54
55
56
57
58
59
60

    KPluginLoader loader(partLib);
    KPluginFactory* factory = loader.factory();
    if (factory) {
        // Create the part
        m_part = factory->create<KParts::ReadOnlyPart>(this, this);
    } else {
61
        KMessageBox::error(this, i18n("No part named %1 found.", partLib));
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    }

    if (m_part) {
        setCentralWidget( m_part->widget() );
        // Integrate its GUI
        createGUI( m_part );
    }

    // Set a reasonable size
    resize( 600, 350 );
}

KPartLoaderWindow::~KPartLoaderWindow()
{
}

78
79
80
81
82
83
void KPartLoaderWindow::aboutKPart()
{
    KAboutApplicationDialog dlg(m_part->componentData(), this);
    dlg.exec();
}

84
85
int main( int argc, char **argv )
{
86
87
    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);

Luigi Toscano's avatar
Luigi Toscano committed
88
89
90
91
    QApplication app(argc, argv);

    KLocalizedString::setApplicationDomain("kpartloader");

92
93
    KAboutData aboutData(
        QStringLiteral("kpartloader"),
94
        i18n("KPartLoader"),
95
96
97
98
        QStringLiteral(KPARTLOADER_VERSION_STRING),
        i18n("This is a test application for KParts."),
        KAboutLicense::GPL
    );
Luigi Toscano's avatar
Luigi Toscano committed
99
    KAboutData::setApplicationData(aboutData);
100
    app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kde-frameworks"), app.windowIcon()));
101

Luigi Toscano's avatar
Luigi Toscano committed
102
103
104
    QCommandLineParser parser;
    aboutData.setupCommandLine(&parser);
    parser.addPositionalArgument(QLatin1String("part"), i18n("Name of the part to load, e.g. dolphinpart"));
105

Luigi Toscano's avatar
Luigi Toscano committed
106
107
108
109
110
    parser.process(app);
    aboutData.processCommandLine(&parser);

    const QStringList args = parser.positionalArguments();
    if ( args.count() == 1 )
111
    {
Luigi Toscano's avatar
Luigi Toscano committed
112
        KPartLoaderWindow *shell = new KPartLoaderWindow(args.at(0));
113
114
115
116
117
        shell->show();
        return app.exec();
    }
    return -1;
}