From 3bac83b229cfeffea40d1ab5ffe07c57f890e404 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 1 Mar 2023 22:37:59 +0900 Subject: KSnapshots: fixed remaining issues related to PR #50. Signed-off-by: Michele Calgaro KSnapshot: remove stray slot This was erroneously introduced in PR #50. Signed-off-by: Mavridis Philippe --- ksnapshot/ksnapshot.cpp | 74 ++++++++++++++++++++++++++++---------------- ksnapshot/ksnapshot.h | 7 ++++- ksnapshot/ksnapshotwidget.ui | 6 ---- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/ksnapshot/ksnapshot.cpp b/ksnapshot/ksnapshot.cpp index c0ab9dd3..7313f103 100644 --- a/ksnapshot/ksnapshot.cpp +++ b/ksnapshot/ksnapshot.cpp @@ -77,12 +77,12 @@ KSnapshot::KSnapshot(TQWidget *parent, const char *name, bool grabCurrent) mainWidget = new KSnapshotWidget( vbox, "mainWidget" ); connect(mainWidget, TQT_SIGNAL(startImageDrag()), TQT_SLOT(slotDragSnapshot())); - - connect( mainWidget, TQT_SIGNAL( newClicked() ), TQT_SLOT( slotGrab() ) ); - connect( mainWidget, TQT_SIGNAL( saveClicked() ), TQT_SLOT( slotSaveAs() ) ); - connect( mainWidget, TQT_SIGNAL( printClicked() ), TQT_SLOT( slotPrint() ) ); - connect( mainWidget, TQT_SIGNAL( copyClicked() ), TQT_SLOT( slotCopy() ) ); - connect( mainWidget, TQT_SIGNAL( openWithKPClicked() ), TQT_SLOT( slotOpenWithKP() ) ); + connect(mainWidget, TQT_SIGNAL(newClicked()), TQT_SLOT(slotGrab())); + connect(mainWidget, TQT_SIGNAL(saveClicked()), TQT_SLOT(slotSaveAs())); + connect(mainWidget, TQT_SIGNAL(printClicked()), TQT_SLOT(slotPrint())); + connect(mainWidget, TQT_SIGNAL(copyClicked()), TQT_SLOT(slotCopy())); + connect(mainWidget, TQT_SIGNAL(openWithKPClicked()), TQT_SLOT(slotOpenWithKP())); + connect(tqApp, TQT_SIGNAL(aboutToQuit()), TQT_SLOT(slotAboutToQuit())); grabber->show(); grabber->grabMouse( waitCursor ); @@ -394,12 +394,10 @@ void KSnapshot::slotOpenWithKP() { } } -static KTempFile *tmpFile = nullptr; - void KSnapshot::openWithExternalApp(const KService &service) { // Write snapshot to temporary file bool ok = false; - tmpFile = new KTempFile; + KTempFile *tmpFile = new KTempFile; if (tmpFile->status() == 0) { if (snapshot.save(tmpFile->file(), "PNG")) { if (tmpFile->close()) { @@ -409,9 +407,9 @@ void KSnapshot::openWithExternalApp(const KService &service) { } if (!ok) { - KMessageBox::error(this, i18n("KSnapshot was unable to create " - "temporary file."), + KMessageBox::error(this, i18n("KSnapshot was unable to create temporary file."), i18n("Unable to save image")); + delete tmpFile; return; } @@ -423,33 +421,55 @@ void KSnapshot::openWithExternalApp(const KService &service) { TDEProcess *externalApp = new TDEProcess; *externalApp << args; connect(externalApp, SIGNAL(processExited(TDEProcess*)), - this, SLOT(slotExternalAppClosed())); + this, SLOT(slotExternalAppClosed(TDEProcess*))); if (!externalApp->start(TDEProcess::OwnGroup)) { KMessageBox::error(this, i18n("Cannot start %1!").arg(service.name())); + delete tmpFile; return; } + + m_tmpFiles[externalApp] = tmpFile; } -void KSnapshot::slotExternalAppClosed() { - snapshot.load(tmpFile->name()); - updatePreview(); - tmpFile->unlink(); - delete tmpFile; - tmpFile = nullptr; +void KSnapshot::slotExternalAppClosed(TDEProcess *process) +{ + if (process && m_tmpFiles.contains(process)) + { + KTempFile *tmpFile = m_tmpFiles[process]; + if (tmpFile) + { + snapshot.load(tmpFile->name()); + updatePreview(); + tmpFile->unlink(); + delete tmpFile; + } + m_tmpFiles.remove(process); + } +} + +void KSnapshot::slotAboutToQuit() +{ + for (KTempFile *tmpFile : m_tmpFiles) + { + tmpFile->unlink(); + delete tmpFile; + } + m_tmpFiles.clear(); + + TDEConfig *conf=TDEGlobal::config(); + conf->setGroup("GENERAL"); + conf->writeEntry("delay",mainWidget->delay()); + conf->writeEntry("mode",mainWidget->mode()); + conf->writeEntry("includeDecorations",mainWidget->includeDecorations()); + KURL url = filename; + url.setPass( TQString() ); + conf->writePathEntry("filename",url.url()); } void KSnapshot::closeEvent( TQCloseEvent * e ) { - TDEConfig *conf=TDEGlobal::config(); - conf->setGroup("GENERAL"); - conf->writeEntry("delay",mainWidget->delay()); - conf->writeEntry("mode",mainWidget->mode()); - conf->writeEntry("includeDecorations",mainWidget->includeDecorations()); - KURL url = filename; - url.setPass( TQString() ); - conf->writePathEntry("filename",url.url()); - e->accept(); + e->accept(); } bool KSnapshot::eventFilter( TQObject* o, TQEvent* e) diff --git a/ksnapshot/ksnapshot.h b/ksnapshot/ksnapshot.h index 5d1edac7..55c0917b 100644 --- a/ksnapshot/ksnapshot.h +++ b/ksnapshot/ksnapshot.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,8 @@ class RegionGrabber; class KSnapshotWidget; +class KTempFile; +class TDEProcess; class KSnapshotPreview : public TQLabel { @@ -101,6 +104,7 @@ public: TQString url() const { return filename.url(); } protected slots: + void slotAboutToQuit(); void slotGrab(); void slotSave(); void slotSaveAs(); @@ -108,7 +112,7 @@ protected slots: void slotPrint(); void slotOpenWith(int id); void slotOpenWithKP(); - void slotExternalAppClosed(); + void slotExternalAppClosed(TDEProcess *process); void slotMovePointer( int x, int y ); void setTime(int newTime); @@ -148,6 +152,7 @@ private: RegionGrabber *rgnGrab; bool modified; TDETrader::OfferList openWithOffers; + TQMap m_tmpFiles; }; #endif // KSNAPSHOT_H diff --git a/ksnapshot/ksnapshotwidget.ui b/ksnapshot/ksnapshotwidget.ui index c2dbf4fd..d0f815c3 100644 --- a/ksnapshot/ksnapshotwidget.ui +++ b/ksnapshot/ksnapshotwidget.ui @@ -323,12 +323,6 @@ If <i>no delay</i> is set, the program will wait for a mouse click b KSnapshotWidget slotOpenWithKPClicked() - - btnOpenWith - clicked() - KSnapshotWidget - slotOpenWithClicked() - btnSave clicked() -- cgit v1.2.1