KSnapshot: Open in KolourPaint

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>

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 <mavridisf@gmail.com>
pull/50/head
Emanoil Kotsev 2 years ago committed by Slávek Banko
parent 513cf6435a
commit db379a2f50
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -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();

@ -14,6 +14,7 @@
#include <tdeglobalsettings.h>
#include <kdialogbase.h>
#include <kurl.h>
#include <ktrader.h>
class RegionGrabber;
class KSnapshotWidget;
@ -21,7 +22,6 @@ class KSnapshotWidget;
class KSnapshotPreview : public TQLabel
{
Q_OBJECT
public:
KSnapshotPreview(TQWidget *parent, const char *name = 0)
@ -90,7 +90,6 @@ class KSnapshotPreview : public TQLabel
class KSnapshot : public KDialogBase, virtual public KSnapshotIface
{
Q_OBJECT
public:
KSnapshot(TQWidget *parent= 0, const char *name= 0, bool grabCurrent=false);
@ -107,6 +106,9 @@ protected slots:
void slotSaveAs();
void slotCopy();
void slotPrint();
void slotOpenWith(int id);
void slotOpenWithKP();
void slotExternalAppClosed();
void slotMovePointer( int x, int y );
void setTime(int newTime);
@ -120,7 +122,7 @@ protected:
virtual void closeEvent( TQCloseEvent * e );
void resizeEvent(TQResizeEvent*);
bool eventFilter( TQObject*, TQEvent* );
private slots:
void grabTimerDone();
void slotDragSnapshot();
@ -131,6 +133,7 @@ private slots:
private:
bool save( const KURL& url );
void openWithExternalApp(const KService &service);
void performGrab();
void autoincFilename();
int grabMode();
@ -144,6 +147,7 @@ private:
KSnapshotWidget *mainWidget;
RegionGrabber *rgnGrab;
bool modified;
TDETrader::OfferList openWithOffers;
};
#endif // KSNAPSHOT_H

@ -242,6 +242,34 @@ If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click b
<string>Click this button to print the current screenshot.</string>
</property>
</widget>
<widget class="KPushButton">
<property name="name">
<cstring>btnOpenWithKP</cstring>
</property>
<property name="text">
<string>Open in &amp;KolourPaint</string>
</property>
<property name="whatsThis" stdset="0">
<string>Click this button to edit the snapshot in KolourPaint.</string>
</property>
<property name="iconSet">
<iconset>"kolourpaint"</iconset>
</property>
</widget>
<widget class="KPushButton">
<property name="name">
<cstring>btnOpenWith</cstring>
</property>
<property name="text">
<string>Open &amp;with...</string>
</property>
<property name="iconSet">
<iconset>"document-open"</iconset>
</property>
<property name="whatsThis" stdset="0">
<string>Click this button to open the snapshot in another application.</string>
</property>
</widget>
</vbox>
</widget>
</grid>
@ -289,6 +317,18 @@ If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click b
<receiver>KSnapshotWidget</receiver>
<slot>slotPrintClicked()</slot>
</connection>
<connection>
<sender>btnOpenWithKP</sender>
<signal>clicked()</signal>
<receiver>KSnapshotWidget</receiver>
<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>
@ -328,6 +368,7 @@ If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click b
<signal>saveClicked()</signal>
<signal>copyClicked()</signal>
<signal>printClicked()</signal>
<signal>openWithKPClicked()</signal>
<signal>startImageDrag()</signal>
</Q_SIGNALS>
<Q_SLOTS>
@ -337,6 +378,7 @@ If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click b
<slot access="protected" specifier="non virtual">slotCopyClicked()</slot>
<slot access="protected" specifier="non virtual">slotPrintClicked()</slot>
<slot access="protected" specifier="non virtual">slotStartDrag()</slot>
<slot access="protected" specifier="non virtual">slotOpenWithKPClicked()</slot>
<slot specifier="non virtual" returnType="int">previewWidth()</slot>
<slot specifier="non virtual" returnType="int">previewHeight()</slot>
</Q_SLOTS>

@ -136,3 +136,8 @@ void KSnapshotWidget::slotCopyClicked()
{
emit copyClicked();
}
void KSnapshotWidget::slotOpenWithKPClicked()
{
emit openWithKPClicked();
}

Loading…
Cancel
Save