diff options
author | Emanoil Kotsev <[email protected]> | 2023-02-26 01:09:35 +0000 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2023-02-28 17:26:31 +0100 |
commit | db379a2f50774d6ab871507356e95715cbf68a7b (patch) | |
tree | 8bbed6cb21cc6dc2ec79969bcb01060c817f066f /ksnapshot/ksnapshot.cpp | |
parent | 513cf6435a2c03911351a2b4e9107fbf4da9d353 (diff) | |
download | tdegraphics-db379a2f50774d6ab871507356e95715cbf68a7b.tar.gz tdegraphics-db379a2f50774d6ab871507356e95715cbf68a7b.zip |
KSnapshot: Open in KolourPaint
Signed-off-by: Emanoil Kotsev <[email protected]>
KSnapshot: Preload screenshot in KolourPaint
Fix preloading a screenshot into KolourPaint by writing data into
a temporary file. When the editor closes and assuming any changes have
been saved to the same temp file, the screenshot data in KSnapshot
get updated, allowing to save the screenshot in the usual way.
KSnapshot: Implement Open With... options using TDETrader
This allows us to dynamically determine which applications can be
used to open the snapshot.
Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'ksnapshot/ksnapshot.cpp')
-rw-r--r-- | ksnapshot/ksnapshot.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/ksnapshot/ksnapshot.cpp b/ksnapshot/ksnapshot.cpp index ad5df57c..c0ab9dd3 100644 --- a/ksnapshot/ksnapshot.cpp +++ b/ksnapshot/ksnapshot.cpp @@ -6,6 +6,7 @@ * (c) Aaron J. Seigo 2002 * (c) Nadeem Hasan 2003 * (c) Bernd Brandstetter 2004 + * (c) Emanoil Kotsev 2023 * * Released under the LGPL see file LICENSE for details. */ @@ -35,6 +36,9 @@ #include <tdepopupmenu.h> #include <kpushbutton.h> #include <tdestartupinfo.h> +#include <kiconloader.h> +#include <kprocess.h> +#include <krun.h> #include <tqcursor.h> #include <tqregexp.h> @@ -78,6 +82,7 @@ KSnapshot::KSnapshot(TQWidget *parent, const char *name, bool grabCurrent) 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() ) ); grabber->show(); grabber->grabMouse( waitCursor ); @@ -115,6 +120,24 @@ KSnapshot::KSnapshot(TQWidget *parent, const char *name, bool grabCurrent) TQPushButton *helpButton = actionButton( Help ); helpButton->setPopup(helpMenu->menu()); + // Populate Open With... menu + TDEPopupMenu *popupOpenWith = new TDEPopupMenu(this); + openWithOffers = TDETrader::self()->query("image/png", "Type == 'Application'"); + int i = 0; + for (TDETrader::OfferList::Iterator it = openWithOffers.begin(); it != openWithOffers.end(); ++it) + { + popupOpenWith->insertItem(SmallIcon((*it)->icon()), (*it)->name(), i); + ++i; // we need menu ids to match with OfferList indexes + } + mainWidget->btnOpenWith->setPopup(popupOpenWith); + connect(popupOpenWith, SIGNAL(activated(int)), this, SLOT(slotOpenWith(int))); + + // Check for KolourPaint availability + KService::Ptr kpaint = KService::serviceByDesktopName("kolourpaint"); + if (!kpaint) { + mainWidget->btnOpenWithKP->hide(); + } + TDEAccel* accel = new TDEAccel(this); accel->insert(TDEStdAccel::Quit, TQT_TQOBJECT(kapp), TQT_SLOT(quit())); accel->insert( "QuickSave", i18n("Quick Save Snapshot &As..."), @@ -359,6 +382,63 @@ void KSnapshot::slotWindowGrabbed( const TQPixmap &pix ) show(); } +void KSnapshot::slotOpenWith(int id) +{ + openWithExternalApp(*openWithOffers[id]); +} + +void KSnapshot::slotOpenWithKP() { + KService::Ptr kpaint = KService::serviceByDesktopName("kolourpaint"); + if (kpaint) { + openWithExternalApp(*kpaint); + } +} + +static KTempFile *tmpFile = nullptr; + +void KSnapshot::openWithExternalApp(const KService &service) { + // Write snapshot to temporary file + bool ok = false; + tmpFile = new KTempFile; + if (tmpFile->status() == 0) { + if (snapshot.save(tmpFile->file(), "PNG")) { + if (tmpFile->close()) { + ok = true; + } + } + } + + if (!ok) { + KMessageBox::error(this, i18n("KSnapshot was unable to create " + "temporary file."), + i18n("Unable to save image")); + return; + } + + // Launch application + KURL::List list; + list.append(tmpFile->name()); + TQStringList args = KRun::processDesktopExec(service, list, false, false); + + TDEProcess *externalApp = new TDEProcess; + *externalApp << args; + connect(externalApp, SIGNAL(processExited(TDEProcess*)), + this, SLOT(slotExternalAppClosed())); + + if (!externalApp->start(TDEProcess::OwnGroup)) { + KMessageBox::error(this, i18n("Cannot start %1!").arg(service.name())); + return; + } +} + +void KSnapshot::slotExternalAppClosed() { + snapshot.load(tmpFile->name()); + updatePreview(); + tmpFile->unlink(); + delete tmpFile; + tmpFile = nullptr; +} + void KSnapshot::closeEvent( TQCloseEvent * e ) { TDEConfig *conf=TDEGlobal::config(); |