summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2023-03-01 22:37:59 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2023-03-02 12:23:54 +0900
commit3bac83b229cfeffea40d1ab5ffe07c57f890e404 (patch)
tree16c40038982e4ef87073af4c3bc1e7d649531cb7
parentdb379a2f50774d6ab871507356e95715cbf68a7b (diff)
downloadtdegraphics-3bac83b229cfeffea40d1ab5ffe07c57f890e404.tar.gz
tdegraphics-3bac83b229cfeffea40d1ab5ffe07c57f890e404.zip
KSnapshots: fixed remaining issues related to PR #50.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> KSnapshot: remove stray slot This was erroneously introduced in PR #50. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--ksnapshot/ksnapshot.cpp74
-rw-r--r--ksnapshot/ksnapshot.h7
-rw-r--r--ksnapshot/ksnapshotwidget.ui6
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 <tqbitmap.h>
#include <tqcursor.h>
#include <tqlabel.h>
+#include <tqmap.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqstyle.h>
@@ -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<TDEProcess*, KTempFile*> 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
@@ -324,12 +324,6 @@ If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click b
<slot>slotOpenWithKPClicked()</slot>
</connection>
<connection>
- <sender>btnOpenWith</sender>
- <signal>clicked()</signal>
- <receiver>KSnapshotWidget</receiver>
- <slot>slotOpenWithClicked()</slot>
- </connection>
- <connection>
<sender>btnSave</sender>
<signal>clicked()</signal>
<receiver>KSnapshotWidget</receiver>