add more spacing
[personal-kdebase.git] / workspace / kcontrol / kfontinst / apps / Viewer.cpp
blobacf4d5424d232d23365013c73b1a9d23a1a26580
1 /*
2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
6 * ----
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.
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.
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.
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>
40 namespace KFI
43 CViewer::CViewer()
45 KPluginFactory *factory=KPluginLoader("kfontviewpart").factory();
47 if(factory)
49 itsPreview=factory->create<KParts::ReadOnlyPart>(this);
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()));
56 itsPrintAct->setEnabled(false);
58 if(itsPreview->browserExtension())
59 connect(itsPreview->browserExtension(), SIGNAL(enableAction(const char *, bool)),
60 this, SLOT(enableAction(const char *, bool)));
62 setCentralWidget(itsPreview->widget());
63 createGUI(itsPreview);
65 setAutoSaveSettings();
66 applyMainWindowSettings(KGlobal::config()->group("MainWindow"));
68 else
69 exit(0);
72 void CViewer::fileOpen()
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);
81 void CViewer::showUrl(const KUrl &url)
83 if(url.isValid())
84 itsPreview->openUrl(url);
87 void CViewer::configureKeys()
89 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
91 dlg.addCollection(actionCollection());
92 dlg.configure();
95 void CViewer::enableAction(const char *name, bool enable)
97 if(0==qstrcmp("print", name))
98 itsPrintAct->setEnabled(enable);
104 class ViewerApplication : public KUniqueApplication
106 public:
108 #ifdef Q_WS_X11
109 ViewerApplication(Display *display, Qt::HANDLE visual, Qt::HANDLE colormap)
110 : KUniqueApplication(display,visual,colormap)
113 #endif
115 ViewerApplication() : KUniqueApplication()
119 int newInstance()
121 KCmdLineArgs *args(KCmdLineArgs::parsedArgs());
122 KFI::CViewer *viewer=new KFI::CViewer;
124 viewer->show();
125 if(args->count() > 0)
127 for (int i = 0; i < args->count(); ++i)
129 KUrl url(args->url(i));
131 if (i != 0)
133 viewer=new KFI::CViewer;
134 viewer->show();
136 viewer->showUrl(url);
140 return 0;
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"));
149 int main(int argc, char **argv)
151 KCmdLineArgs::init(argc, argv, &aboutData);
152 KCmdLineArgs::addTempFileOption();
154 KCmdLineOptions options;
155 options.add("+[URL]", ki18n("URL to open"));
156 KCmdLineArgs::addCmdLineOptions(options);
158 if (!KUniqueApplication::start())
159 exit(0);
161 KFI::ViewerApplication app;
163 return app.exec();
166 #include "Viewer.moc"