~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kcontrol/kfontinst/apps/Viewer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * KFontInst - KDE Font Installer
 
3
 *
 
4
 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
 
5
 *
 
6
 * ----
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU General Public
 
10
 * License version 2 as published by the Free Software Foundation.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; see the file COPYING.  If not, write to
 
19
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
20
 * Boston, MA 02110-1301, USA.
 
21
 */
 
22
 
 
23
#include "Viewer.h"
 
24
#include "KfiConstants.h"
 
25
#include <kcmdlineargs.h>
 
26
#include <kaboutdata.h>
 
27
#include <kapplication.h>
 
28
#include <klibloader.h>
 
29
#include <klocale.h>
 
30
#include <kglobal.h>
 
31
#include <kfiledialog.h>
 
32
#include <kconfig.h>
 
33
#include <kstandardaction.h>
 
34
#include <kactioncollection.h>
 
35
#include <kparts/browserextension.h>
 
36
 
 
37
#define CFG_GROUP    "FontViewer Settings"
 
38
#define CFG_SIZE_KEY "Window Size"
 
39
 
 
40
namespace KFI
 
41
{
 
42
 
 
43
CViewer::CViewer()
 
44
{
 
45
    KPluginFactory *factory=KLibLoader::self()->factory("libkfontviewpart");
 
46
 
 
47
    if(factory)
 
48
    {
 
49
        itsPreview=factory->create<KParts::ReadOnlyPart>(this);
 
50
 
 
51
        actionCollection()->addAction(KStandardAction::Open, this, SLOT(fileOpen()));
 
52
        actionCollection()->addAction(KStandardAction::Quit, kapp, SLOT(quit()));
 
53
        itsPrintAct=actionCollection()->addAction(KStandardAction::Print, itsPreview, SLOT(print()));
 
54
 
 
55
        itsPrintAct->setEnabled(false);
 
56
 
 
57
        if(itsPreview->browserExtension())
 
58
            connect(itsPreview->browserExtension(), SIGNAL(enableAction(const char *, bool)),
 
59
                    this, SLOT(enableAction(const char *, bool)));
 
60
 
 
61
        setCentralWidget(itsPreview->widget());
 
62
        createGUI(itsPreview);
 
63
 
 
64
        KCmdLineArgs *args(KCmdLineArgs::parsedArgs());
 
65
 
 
66
        if(args->count() > 0)
 
67
        {
 
68
            KUrl url(args->url(args->count() - 1));
 
69
 
 
70
            if(url.isValid())
 
71
                itsPreview->openUrl(url);
 
72
        }
 
73
 
 
74
        QSize defSize(440, 530);
 
75
 
 
76
        resize(KGlobal::config()->group(CFG_GROUP).readEntry(CFG_SIZE_KEY, defSize));
 
77
    }
 
78
    else
 
79
        exit(0);
 
80
}
 
81
 
 
82
CViewer::~CViewer()
 
83
{
 
84
    KGlobal::config()->group(CFG_GROUP).writeEntry(CFG_SIZE_KEY, size());
 
85
    KGlobal::config()->sync();
 
86
}
 
87
 
 
88
void CViewer::fileOpen()
 
89
{
 
90
    KUrl url(KFileDialog::getOpenUrl(KUrl(), "application/x-font-ttf application/x-font-otf "
 
91
                                             "application/x-font-type1 "
 
92
                                             "application/x-font-bdf application/x-font-pcf ",
 
93
                                     this, i18n("Select Font to View")));
 
94
    if(url.isValid())
 
95
        itsPreview->openUrl(url);
 
96
}
 
97
 
 
98
void CViewer::enableAction(const char *name, bool enable)
 
99
{
 
100
    if(0==qstrcmp("print", name))
 
101
        itsPrintAct->setEnabled(enable);
 
102
}
 
103
 
 
104
}
 
105
 
 
106
static KAboutData aboutData("kfontview", KFI_CATALOGUE, ki18n("Font Viewer"), "1.1", ki18n("Simple font viewer"),
 
107
                            KAboutData::License_GPL, ki18n("(C) Craig Drummond, 2004-2007"));
 
108
 
 
109
int main(int argc, char **argv)
 
110
{
 
111
    KCmdLineArgs::init(argc, argv, &aboutData);
 
112
 
 
113
    KCmdLineOptions options;
 
114
    options.add("+[URL]", ki18n("URL to open"));
 
115
    KCmdLineArgs::addCmdLineOptions(options);
 
116
 
 
117
    KApplication app;
 
118
 
 
119
    KFI::CViewer *viewer=new KFI::CViewer;
 
120
 
 
121
    viewer->show();
 
122
    return app.exec();
 
123
}
 
124
 
 
125
#include "Viewer.moc"