~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

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 modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; see the file COPYING.  If not, write to
 
20
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
21
 * Boston, MA 02110-1301, USA.
 
22
 */
 
23
 
 
24
#include "Viewer.h"
 
25
#include "KfiConstants.h"
 
26
#include <KDE/KCmdLineArgs>
 
27
#include <KDE/KAboutData>
 
28
#include <KDE/KUniqueApplication>
 
29
#include <KDE/KPluginLoader>
 
30
#include <KDE/KPluginFactory>
 
31
#include <KDE/KLocale>
 
32
#include <KDE/KGlobal>
 
33
#include <KDE/KFileDialog>
 
34
#include <KDE/KConfig>
 
35
#include <KDE/KStandardAction>
 
36
#include <KDE/KActionCollection>
 
37
#include <KDE/KShortcutsDialog>
 
38
#include <KDE/KParts/BrowserExtension>
 
39
 
 
40
namespace KFI
 
41
{
 
42
 
 
43
CViewer::CViewer()
 
44
{
 
45
    KPluginFactory *factory=KPluginLoader("kfontviewpart").factory();
 
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, this, SLOT(close()));
 
53
        actionCollection()->addAction(KStandardAction::KeyBindings, this, SLOT(configureKeys()));
 
54
        itsPrintAct=actionCollection()->addAction(KStandardAction::Print, itsPreview, SLOT(print()));
 
55
 
 
56
        itsPrintAct->setEnabled(false);
 
57
 
 
58
        if(itsPreview->browserExtension())
 
59
            connect(itsPreview->browserExtension(), SIGNAL(enableAction(const char *, bool)),
 
60
                    this, SLOT(enableAction(const char *, bool)));
 
61
 
 
62
        setCentralWidget(itsPreview->widget());
 
63
        createGUI(itsPreview);
 
64
 
 
65
        setAutoSaveSettings();
 
66
        applyMainWindowSettings(KGlobal::config()->group("MainWindow"));
 
67
    }
 
68
    else
 
69
        exit(0);
 
70
}
 
71
 
 
72
void CViewer::fileOpen()
 
73
{
 
74
    KUrl url(KFileDialog::getOpenUrl(KUrl(), "application/x-font-ttf application/x-font-otf "
 
75
                                             "application/x-font-type1 "
 
76
                                             "application/x-font-bdf application/x-font-pcf ",
 
77
                                     this, i18n("Select Font to View")));
 
78
    showUrl(url);
 
79
}
 
80
 
 
81
void CViewer::showUrl(const KUrl &url)
 
82
{
 
83
    if(url.isValid())
 
84
        itsPreview->openUrl(url);
 
85
}
 
86
 
 
87
void CViewer::configureKeys()
 
88
{
 
89
    KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
 
90
 
 
91
    dlg.addCollection(actionCollection());
 
92
    dlg.configure();
 
93
}
 
94
 
 
95
void CViewer::enableAction(const char *name, bool enable)
 
96
{
 
97
    if(0==qstrcmp("print", name))
 
98
        itsPrintAct->setEnabled(enable);
 
99
}
 
100
 
 
101
 
 
102
 
 
103
 
 
104
class ViewerApplication : public KUniqueApplication
 
105
{
 
106
    public:
 
107
 
 
108
#ifdef Q_WS_X11
 
109
    ViewerApplication(Display *display, Qt::HANDLE visual, Qt::HANDLE colormap)
 
110
        : KUniqueApplication(display,visual,colormap)
 
111
    {
 
112
    }
 
113
#endif
 
114
 
 
115
    ViewerApplication() : KUniqueApplication()
 
116
    {
 
117
    }
 
118
 
 
119
    int newInstance()
 
120
    {
 
121
        KCmdLineArgs *args(KCmdLineArgs::parsedArgs());
 
122
        KFI::CViewer *viewer=new KFI::CViewer;
 
123
 
 
124
        viewer->show();
 
125
        if(args->count() > 0)
 
126
        {
 
127
            for (int i = 0; i < args->count(); ++i)
 
128
            {
 
129
                KUrl url(args->url(i));
 
130
 
 
131
                if (i != 0)
 
132
                {
 
133
                    viewer=new KFI::CViewer;
 
134
                    viewer->show();
 
135
                }
 
136
                viewer->showUrl(url);
 
137
            }
 
138
        }
 
139
 
 
140
        return 0;
 
141
    }
 
142
};
 
143
 
 
144
}
 
145
 
 
146
static KAboutData aboutData("kfontview", KFI_CATALOGUE, ki18n("Font Viewer"), "1.1", ki18n("Simple font viewer"),
 
147
                            KAboutData::License_GPL, ki18n("(C) Craig Drummond, 2004-2007"));
 
148
 
 
149
int main(int argc, char **argv)
 
150
{
 
151
    KCmdLineArgs::init(argc, argv, &aboutData);
 
152
    KCmdLineArgs::addTempFileOption();
 
153
 
 
154
    KCmdLineOptions options;
 
155
    options.add("+[URL]", ki18n("URL to open"));
 
156
    KCmdLineArgs::addCmdLineOptions(options);
 
157
 
 
158
    if (!KUniqueApplication::start())
 
159
        exit(0);
 
160
 
 
161
    KFI::ViewerApplication app;
 
162
 
 
163
    return app.exec();
 
164
}
 
165
 
 
166
#include "Viewer.moc"