[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegraphics/kviewshell/shell
From: Stefan Kebekus <kebekus () kde ! org>
Date: 2006-08-22 6:55:54
Message-ID: 1156229754.450796.17148.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 575817 by kebekus:
added library version check; ported from kvs 0.7
M +1 -0 kviewpart.h
M +103 -49 kviewshell.cpp
--- trunk/KDE/kdegraphics/kviewshell/shell/kviewpart.h #575816:575817
@@ -42,6 +42,7 @@
class KViewPart: public KParts::ReadWritePart
{
Q_OBJECT
+ Q_CLASSINFO("Version", "Version 1 for KDE 4")
public:
--- trunk/KDE/kdegraphics/kviewshell/shell/kviewshell.cpp #575816:575817
@@ -67,57 +67,86 @@
KLibFactory *factory = KLibLoader::self()->factory("kviewerpart");
if (factory) {
if (defaultMimeType == QString::null)
- {
view = static_cast<KViewPart*>(factory->create(this, "KViewPart"));
- }
- else
- {
+ else {
QStringList args;
args << defaultMimeType;
view = static_cast<KViewPart*>(factory->create(this, "KViewPart", args));
}
- if (!view)
- {
+ if (!view) {
kError() << "FATAL ERROR: Loading of the KViewPart failed. Aborting..." << \
endl; ::exit(-1);
}
- } else {
- KMessageBox::error(this, i18n("No viewing component found"));
- ::exit(-1);
+ } else
+ KMessageBox::detailedError(this,
+ i18n("<qt>A fatal error ocurred. An important library \
could not be found. KViewShell will not work.</qt>"), + \
i18n("<qt><p>The KViewShell application uses the<strong>kviewerpart</strong> library \
internally. " + "This library was not found on \
your computer.</p>" + "<p>The problem is most \
likely a broken installation of the KViewShell application. " + \
"You could try to uninstall all instances of KViewShell and then re-install the \
latest version.</p></qt>"), + i18n("KViewShell - \
Critical Error")); +
+ if (view != 0) {
+ QString version;
+ int idx = view->metaObject()->indexOfClassInfo("Version");
+ if (idx >= 0)
+ version = view->metaObject()->classInfo(idx).value();
+
+ QString expectedVersion("Version 1 for KDE 4");
+ if (version != expectedVersion) {
+ if (version.isEmpty())
+ version = "Version 0, probaby from KDE 3.4 or older";
+ KMessageBox::detailedError(this,
+ i18n("<qt>A fatal error ocurred. An incompatible \
version of an important library was found. KViewShell will not work.</qt>"), + \
i18n("<qt><p>The KViewShell application uses the <strong>kviewerpart</strong> library \
internally. " + "A version of this library was \
found, but this version is <strong>not</strong> compatible with the current version " \
+ "of the KViewShell application.</p>" + \
"<p>Version found: <strong>%1</strong></p>" + \
"<p>Version required: <strong>%2</strong></p>" + \
"<p>The problem is most likely that two incompatible versions of KViewShell are \
simultaneously installed on your computer. " + \
"You could try to uninstall all instances of KViewShell and then re-install the \
latest version.</p></qt>", + version, \
expectedVersion), + i18n("KViewShell - Critical \
Error")); + delete view;
+ view = 0;
+ }
}
+
- setCentralWidget(view->widget());
+ if (view != 0)
+ setCentralWidget(view->widget());
// file menu
- KStdAction::open(view, SLOT(slotFileOpen()), actionCollection());
- recent = KStdAction::openRecent (this, SLOT(openURL(const KUrl &)), \
actionCollection());
- reloadAction = new KAction(KIcon("reload"), i18n("Reload"), actionCollection(), \
"reload");
- connect(reloadAction, SIGNAL(triggered(bool)), view, SLOT(reload(void)));
- reloadAction->setShortcut(Qt::CTRL + Qt::Key_R);
- closeAction = KStdAction::close(this, SLOT(slotFileClose()), actionCollection());
+ if (view != 0) {
+ KStdAction::open(view, SLOT(slotFileOpen()), actionCollection());
+ recent = KStdAction::openRecent (this, SLOT(openURL(const KUrl &)), \
actionCollection()); + reloadAction = new KAction(KIcon("reload"), i18n("Reload"), \
actionCollection(), "reload"); + connect(reloadAction, SIGNAL(triggered(bool)), \
view, SLOT(reload(void))); + reloadAction->setShortcut(Qt::CTRL + Qt::Key_R);
+ closeAction = KStdAction::close(this, SLOT(slotFileClose()), \
actionCollection()); + connect(view, SIGNAL(fileOpened()), this, \
SLOT(addRecentFile())); + }
KStdAction::quit (this, SLOT(slotQuit()), actionCollection());
- connect(view, SIGNAL(fileOpened()), this, SLOT(addRecentFile()));
-
// view menu
fullScreenAction = KStdAction::fullScreen(this, SLOT(slotFullScreen()), \
actionCollection(), this, "fullscreen" );
createStandardStatusBarAction();
-
setStandardToolBarMenuEnabled(true);
KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection());
KStdAction::configureToolbars(this, SLOT(slotEditToolbar()), actionCollection());
- // statusbar connects
- connect( view, SIGNAL( zoomChanged(const QString &) ), this,SLOT( \
slotChangeZoomText(const QString &) ) );
- connect( view, SIGNAL( pageChanged(const QString &) ), this,SLOT( \
slotChangePageText(const QString &) ) );
- connect( view, SIGNAL( sizeChanged(const QString &) ), this,SLOT( \
slotChangeSizeText(const QString &) ) ); + if (view != 0) {
+ // statusbar connects
+ connect( view, SIGNAL( zoomChanged(const QString &) ), this,SLOT( \
slotChangeZoomText(const QString &) ) ); + connect( view, SIGNAL( \
pageChanged(const QString &) ), this,SLOT( slotChangePageText(const QString &) ) ); + \
connect( view, SIGNAL( sizeChanged(const QString &) ), this,SLOT( \
slotChangeSizeText(const QString &) ) ); + // Setup session management
+ connect( this, SIGNAL( restoreDocument(const KUrl &, int) ), view, SLOT( \
restoreDocument(const KUrl &, int))); + connect( this, SIGNAL( \
saveDocumentRestoreInfo(KConfig*) ), view, SLOT( saveDocumentRestoreInfo(KConfig*))); \
+ }
- // Setup session management
- connect( this, SIGNAL( restoreDocument(const KUrl &, int) ), view, SLOT( \
restoreDocument(const KUrl &, int)));
- connect( this, SIGNAL( saveDocumentRestoreInfo(KConfig*) ), view, SLOT( \
saveDocumentRestoreInfo(KConfig*)));
-
setXMLFile( "kviewshell.rc" );
createGUI(view);
readSettings();
@@ -141,13 +170,18 @@
statusBar()->insertPermanentItem("", StatusBar_ID_PageSize, 0);
- connect(view, SIGNAL(switchTool(int)), toolIndicator, SLOT(slotSwitchTool(int)));
- connect(view, SIGNAL(registerTool(int, QPixmap)), toolIndicator, \
SLOT(slotRegisterTool(int, QPixmap))); + if (view != 0) {
+ connect(view, SIGNAL(switchTool(int)), toolIndicator, \
SLOT(slotSwitchTool(int))); + connect(view, SIGNAL(registerTool(int, QPixmap)), \
toolIndicator, SLOT(slotRegisterTool(int, QPixmap))); + }
}
void KViewShell::checkActions()
{
+ if (view == 0)
+ return;
+
bool doc = !view->url().isEmpty();
closeAction->setEnabled(doc);
@@ -160,8 +194,7 @@
{
writeSettings();
- if (tmpFile)
- {
+ if (tmpFile) {
tmpFile->setAutoRemove(true);
delete tmpFile;
tmpFile = 0;
@@ -212,21 +245,22 @@
KConfig *config = KGlobal::config();
config->setGroup("General");
- recent->loadEntries(config, "Recent Files");
-
- // Constant source of annoyance in KDVI < 1.0: the 'recent-files'
- // menu contains lots of files which don't exist (any longer). Thus,
- // we'll sort out the non-existent files here.
- QStringList items = recent->items();
- for ( QStringList::Iterator it = items.begin(); it != items.end(); ++it ) {
- KUrl url(*it);
- if (url.isLocalFile()) {
- QFileInfo info(url.path());
- if (!info.exists())
- recent->removeUrl(url);
+ if (recent != 0) {
+ recent->loadEntries(config, "Recent Files");
+
+ // Constant source of annoyance in KDVI < 1.0: the 'recent-files'
+ // menu contains lots of files which don't exist (any longer). Thus,
+ // we'll sort out the non-existent files here.
+ QStringList items = recent->items();
+ for ( QStringList::Iterator it = items.begin(); it != items.end(); ++it ) {
+ KUrl url(*it);
+ if (url.isLocalFile()) {
+ QFileInfo info(url.path());
+ if (!info.exists())
+ recent->removeUrl(url);
+ }
}
}
-
}
@@ -234,7 +268,8 @@
{
KConfig *config = KGlobal::config();
config->setGroup( "General" );
- recent->saveEntries(config, "Recent Files");
+ if (recent != 0)
+ recent->saveEntries(config, "Recent Files");
config->sync();
}
@@ -255,8 +290,7 @@
// config file. this function is automatically called whenever
// the app is being restored. read in here whatever you wrote
// in 'saveProperties'
- if (view)
- {
+ if (view) {
KUrl url (config->readPathEntry("URL"));
if (url.isValid())
emit restoreDocument(url, config->readEntry("Page", 1));
@@ -266,6 +300,9 @@
void KViewShell::addRecentFile()
{
+ if (view == 0)
+ return;
+
// Get the URL of the opened file from the kviewpart.
KUrl actualURL = view->url();
// To store the URL in the list of recent files, we remove the
@@ -277,14 +314,19 @@
void KViewShell::openURL(const KUrl& url)
{
+ if (view == 0)
+ return;
+
view->openURL(url);
}
void KViewShell::openStdin()
{
- if (tmpFile)
- {
+ if (view == 0)
+ return;
+
+ if (tmpFile) {
tmpFile->setAutoRemove(true);
delete tmpFile;
}
@@ -323,6 +365,9 @@
void KViewShell::slotFullScreen()
{
+ if (view == 0)
+ return;
+
if (fullScreenAction->isChecked()) {
// In fullscreen mode, menu- tool- and statusbar are hidden. Save
// the visibility flags of these objects here, so that they can
@@ -353,6 +398,9 @@
void KViewShell::slotFileClose()
{
+ if (view == 0)
+ return;
+
view->closeURL();
checkActions();
@@ -387,6 +435,9 @@
void KViewShell::dragEnterEvent(QDragEnterEvent *event)
{
+ if (view == 0)
+ return;
+
if (K3URLDrag::canDecode(event))
{
KUrl::List urls;
@@ -432,6 +483,9 @@
void KViewShell::dropEvent(QDropEvent *event)
{
+ if (view == 0)
+ return;
+
KUrl::List urls;
if (K3URLDrag::decode(event, urls) && !urls.isEmpty())
view->openURL(urls.first());
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic