~ubuntu-branches/ubuntu/warty/kdebase/warty

« back to all changes in this revision

Viewing changes to kicker/proxy/extensiondebugger.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-09-16 04:51:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040916045145-9vr63kith3k1cpza
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
Copyright (c) 2000 Matthias Elter <elter@kde.org>
 
4
 
 
5
Permission is hereby granted, free of charge, to any person obtaining a copy
 
6
of this software and associated documentation files (the "Software"), to deal
 
7
in the Software without restriction, including without limitation the rights
 
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
copies of the Software, and to permit persons to whom the Software is
 
10
furnished to do so, subject to the following conditions:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTDHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
******************************************************************/
 
23
 
 
24
#include <qfile.h>
 
25
#include <qlayout.h>
 
26
#include <qpushbutton.h>
 
27
 
 
28
#include <kapplication.h>
 
29
#include <kglobal.h>
 
30
#include <klocale.h>
 
31
#include <kstandarddirs.h>
 
32
#include <kcmdlineargs.h>
 
33
#include <kdebug.h>
 
34
#include <kpanelextension.h>
 
35
#include <kaboutdata.h>
 
36
#include <qfileinfo.h>
 
37
 
 
38
#include "pluginloader.h"
 
39
#include "appletinfo.h"
 
40
#include "extensiondebugger.h"
 
41
#include "extensiondebugger.moc"
 
42
 
 
43
 
 
44
 
 
45
static KCmdLineOptions options[] =
 
46
{
 
47
  { "+desktopfile", I18N_NOOP("The extensions desktop file."), 0 },
 
48
  KCmdLineLastOption
 
49
};
 
50
 
 
51
int main( int argc, char ** argv )
 
52
{
 
53
    KAboutData aboutData( "extensionproxy", I18N_NOOP("Panel extension proxy.")
 
54
                          , "v0.1.0"
 
55
                          ,I18N_NOOP("Panel extension proxy.")
 
56
                          , KAboutData::License_BSD
 
57
                          , "(c) 2000, The KDE Developers");
 
58
    KCmdLineArgs::init(argc, argv, &aboutData );
 
59
    aboutData.addAuthor("Matthias Elter",0, "elter@kde.org");
 
60
    aboutData.addAuthor("Matthias Ettrich",0, "ettrich@kde.org");
 
61
    KApplication::addCmdLineOptions();
 
62
    KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
 
63
 
 
64
    KApplication a;
 
65
    a.disableSessionManagement();
 
66
 
 
67
    KGlobal::dirs()->addResourceType("extensions", KStandardDirs::kde_default("data") +
 
68
                                     "kicker/extensions");
 
69
 
 
70
    QString df;
 
71
 
 
72
    // parse cmdline args
 
73
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
74
 
 
75
    // sanity check
 
76
    if ( args->count() == 0 )
 
77
        KCmdLineArgs::usage(i18n("No desktop file specified") );
 
78
 
 
79
 
 
80
    QCString desktopFile = QCString( args->arg(0) );
 
81
 
 
82
    // try simple path first
 
83
    QFileInfo finfo( desktopFile );
 
84
    if ( finfo.exists() ) {
 
85
        df = finfo.absFilePath();
 
86
    } else {
 
87
        // locate desktop file
 
88
        df = KGlobal::dirs()->findResource("extensions", QString(desktopFile));
 
89
    }
 
90
 
 
91
    // does the config file exist?
 
92
    if (!QFile::exists(df)) {
 
93
        kdError() << "Failed to locate extension desktop file: " << desktopFile << endl;
 
94
        return 1;
 
95
    }
 
96
 
 
97
    AppletInfo info( df );
 
98
 
 
99
    KPanelExtension *extension = PluginLoader::pluginLoader()->loadExtension( info, 0 );
 
100
    if ( !extension ) {
 
101
        kdError() << "Failed to load extension: " << info.library() << endl;
 
102
        return 1;
 
103
    }
 
104
 
 
105
    ExtensionContainer *container = new ExtensionContainer( extension );
 
106
    container->show();
 
107
 
 
108
    QObject::connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
 
109
 
 
110
    int result = a.exec();
 
111
 
 
112
    delete extension;
 
113
 
 
114
    return result;
 
115
}
 
116
 
 
117
ExtensionContainer::ExtensionContainer( KPanelExtension *extension, QWidget *parent, const char *name )
 
118
    : QWidget( parent, name ), m_extension( extension )
 
119
{
 
120
    ( new QVBoxLayout( this ) )->setAutoAdd( true );
 
121
 
 
122
    QPushButton *configButton = new QPushButton( i18n( "Configure..." ), this );
 
123
    connect( configButton, SIGNAL( clicked() ),
 
124
             this, SLOT( showPreferences() ) );
 
125
 
 
126
    m_extension->reparent( this, QPoint( 0, 0 ) );
 
127
}
 
128
 
 
129
void ExtensionContainer::resizeEvent( QResizeEvent * )
 
130
{
 
131
    m_extension->setGeometry( 0, 0, width(), height() );
 
132
}
 
133
 
 
134
void ExtensionContainer::showPreferences()
 
135
{
 
136
    m_extension->action( KPanelExtension::Preferences );
 
137
}