summaryrefslogtreecommitdiffstats
path: root/ksnapshot
diff options
context:
space:
mode:
Diffstat (limited to 'ksnapshot')
-rw-r--r--ksnapshot/CMakeL10n.txt6
-rw-r--r--ksnapshot/CMakeLists.txt2
-rw-r--r--ksnapshot/ksnapshot.cpp514
-rw-r--r--ksnapshot/ksnapshot.desktop83
-rw-r--r--ksnapshot/ksnapshot.h50
-rw-r--r--ksnapshot/ksnapshotiface.h5
-rw-r--r--ksnapshot/ksnapshotwidget.ui44
-rw-r--r--ksnapshot/ksnapshotwidget.ui.h11
-rw-r--r--ksnapshot/regiongrabber.cpp8
-rw-r--r--ksnapshot/regiongrabber.h2
-rw-r--r--ksnapshot/windowgrabber.cpp4
-rw-r--r--ksnapshot/windowgrabber.h2
12 files changed, 477 insertions, 254 deletions
diff --git a/ksnapshot/CMakeL10n.txt b/ksnapshot/CMakeL10n.txt
index d472e741..6e40132a 100644
--- a/ksnapshot/CMakeL10n.txt
+++ b/ksnapshot/CMakeL10n.txt
@@ -1,3 +1,9 @@
##### create translation templates ##############
tde_l10n_create_template( "ksnapshot" )
+
+tde_l10n_create_template(
+ CATALOG "desktop_files/ksnapshot.desktop/"
+ SOURCES ksnapshot.desktop
+ DESTINATION "${CMAKE_SOURCE_DIR}/translations"
+)
diff --git a/ksnapshot/CMakeLists.txt b/ksnapshot/CMakeLists.txt
index a9b0fcdd..93fc591b 100644
--- a/ksnapshot/CMakeLists.txt
+++ b/ksnapshot/CMakeLists.txt
@@ -31,7 +31,7 @@ link_directories(
##### other data ################################
tde_install_icons( ksnapshot )
-install( FILES ksnapshot.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
+tde_create_translated_desktop( ksnapshot.desktop )
##### ksnapshot (executable) ####################
diff --git a/ksnapshot/ksnapshot.cpp b/ksnapshot/ksnapshot.cpp
index ad5df57c..36918c4a 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.
*/
@@ -21,10 +22,11 @@
#include <kprinter.h>
#include <tdeio/netaccess.h>
#include <ksavefile.h>
+#include <tdestandarddirs.h>
#include <tdetempfile.h>
+#include <kde_file.h>
#include <tqbitmap.h>
-#include <tqdragobject.h>
#include <tqimage.h>
#include <tqclipboard.h>
#include <tqvbox.h>
@@ -35,6 +37,9 @@
#include <tdepopupmenu.h>
#include <kpushbutton.h>
#include <tdestartupinfo.h>
+#include <kiconloader.h>
+#include <tdeprocess.h>
+#include <krun.h>
#include <tqcursor.h>
#include <tqregexp.h>
@@ -42,8 +47,15 @@
#include <tqpaintdevicemetrics.h>
#include <tqwhatsthis.h>
+#include <functional>
+#include <memory>
+#include <utility>
+
#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+
#include "ksnapshot.h"
#include "regiongrabber.h"
#include "windowgrabber.h"
@@ -56,11 +68,29 @@
#include <tdeglobal.h>
-#define kApp TDEApplication::kApplication()
+// A quick and dirty scope guard implementation
+class ExitGuard {
+public:
+ template<class Callable>
+ ExitGuard(Callable && undo_func) : f(std::forward<Callable>(undo_func)) {}
+ ExitGuard(ExitGuard && other) : f(std::move(other.f)) {
+ other.f = nullptr;
+ }
+
+ ~ExitGuard() {
+ if(f) { f(); f = nullptr; }
+ }
+
+ ExitGuard(const ExitGuard&) = delete;
+ void operator= (const ExitGuard&) = delete;
+
+private:
+ std::function<void()> f;
+};
KSnapshot::KSnapshot(TQWidget *parent, const char *name, bool grabCurrent)
- : DCOPObject("interface"),
- KDialogBase(parent, name, true, TQString(), Help|User1, User1,
+ : DCOPObject("interface"),
+ KDialogBase(parent, name, true, TQString(), Help|User1, User1,
true, KStdGuiItem::quit() )
{
grabber = new TQWidget( 0, 0, WStyle_Customize | WX11BypassWM );
@@ -72,22 +102,25 @@ KSnapshot::KSnapshot(TQWidget *parent, const char *name, bool grabCurrent)
TQVBox *vbox = makeVBoxMainWidget();
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, TQ_SIGNAL(startImageDrag()), TQ_SLOT(slotDragSnapshot()));
+ connect(mainWidget, TQ_SIGNAL(newClicked()), TQ_SLOT(slotGrab()));
+ connect(mainWidget, TQ_SIGNAL(saveClicked()), TQ_SLOT(slotSaveAs()));
+ connect(mainWidget, TQ_SIGNAL(printClicked()), TQ_SLOT(slotPrint()));
+ connect(mainWidget, TQ_SIGNAL(copyClicked()), TQ_SLOT(slotCopy()));
+ connect(mainWidget, TQ_SIGNAL(openWithKPClicked()), TQ_SLOT(slotOpenWithKP()));
+ connect(tqApp, TQ_SIGNAL(aboutToQuit()), TQ_SLOT(slotAboutToQuit()));
grabber->show();
grabber->grabMouse( waitCursor );
- if ( !grabCurrent )
- snapshot = TQPixmap::grabWindow( tqt_xrootwin() );
- else {
- mainWidget->setMode( WindowUnderCursor );
- mainWidget->setIncludeDecorations( true );
- performGrab();
+ if ( !grabCurrent ) {
+ snapshot = TQPixmap::grabWindow( tqt_xrootwin() );
+ timestamp = TQDateTime::currentDateTime();
+ setLocalFilePath(TQString::null);
+ } else {
+ mainWidget->setMode( WindowUnderCursor );
+ mainWidget->setIncludeDecorations( true );
+ performGrab();
}
updatePreview();
@@ -103,54 +136,74 @@ KSnapshot::KSnapshot(TQWidget *parent, const char *name, bool grabCurrent)
// Make sure the name is not already being used
while(TDEIO::NetAccess::exists( filename, false, this )) {
- autoincFilename();
+ autoincFilename();
}
- connect( &grabTimer, TQT_SIGNAL( timeout() ), TQT_TQOBJECT(this), TQT_SLOT( grabTimerDone() ) );
- connect( &updateTimer, TQT_SIGNAL( timeout() ), TQT_TQOBJECT(this), TQT_SLOT( updatePreview() ) );
- TQTimer::singleShot( 0, TQT_TQOBJECT(this), TQT_SLOT( updateCaption() ) );
+ connect( &grabTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( grabTimerDone() ) );
+ connect( &updateTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( updatePreview() ) );
+ TQTimer::singleShot( 0, this, TQ_SLOT( updateCaption() ) );
KHelpMenu *helpMenu = new KHelpMenu(this, TDEGlobal::instance()->aboutData(), false);
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, TQ_SIGNAL(activated(int)), this, TQ_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(TDEStdAccel::Quit, tdeApp, TQ_SLOT(quit()));
accel->insert( "QuickSave", i18n("Quick Save Snapshot &As..."),
- i18n("Save the snapshot to the file specified by the user without showing the file dialog."),
- CTRL+SHIFT+Key_S, TQT_TQOBJECT(this), TQT_SLOT(slotSave()));
- accel->insert(TDEStdAccel::Save, TQT_TQOBJECT(this), TQT_SLOT(slotSaveAs()));
-// accel->insert(TDEShortcut(CTRL+Key_A), TQT_TQOBJECT(this), TQT_SLOT(slotSaveAs()));
+ i18n("Save the snapshot to the file specified by the user without showing the file dialog."),
+ CTRL+SHIFT+Key_S, this, TQ_SLOT(slotSave()));
+ accel->insert(TDEStdAccel::Save, this, TQ_SLOT(slotSaveAs()));
+// accel->insert(TDEShortcut(CTRL+Key_A), this, TQ_SLOT(slotSaveAs()));
accel->insert( "SaveAs", i18n("Save Snapshot &As..."),
- i18n("Save the snapshot to the file specified by the user."),
- CTRL+Key_A, TQT_TQOBJECT(this), TQT_SLOT(slotSaveAs()));
- accel->insert(TDEStdAccel::Print, TQT_TQOBJECT(this), TQT_SLOT(slotPrint()));
- accel->insert(TDEStdAccel::New, TQT_TQOBJECT(this), TQT_SLOT(slotGrab()));
- accel->insert(TDEStdAccel::Copy, TQT_TQOBJECT(this), TQT_SLOT(slotCopy()));
-
- accel->insert( "Quit2", Key_Q, TQT_TQOBJECT(this), TQT_SLOT(slotSave()));
- accel->insert( "Save2", Key_S, TQT_TQOBJECT(this), TQT_SLOT(slotSaveAs()));
- accel->insert( "Print2", Key_P, TQT_TQOBJECT(this), TQT_SLOT(slotPrint()));
- accel->insert( "New2", Key_N, TQT_TQOBJECT(this), TQT_SLOT(slotGrab()));
- accel->insert( "New3", Key_Space, TQT_TQOBJECT(this), TQT_SLOT(slotGrab()));
+ i18n("Save the snapshot to the file specified by the user."),
+ CTRL+Key_A, this, TQ_SLOT(slotSaveAs()));
+ accel->insert(TDEStdAccel::Print, this, TQ_SLOT(slotPrint()));
+ accel->insert(TDEStdAccel::New, this, TQ_SLOT(slotGrab()));
+ accel->insert(TDEStdAccel::Copy, this, TQ_SLOT(slotCopy()));
+
+ accel->insert( "Quit2", Key_Q, this, TQ_SLOT(slotSave()));
+ accel->insert( "Save2", Key_S, this, TQ_SLOT(slotSaveAs()));
+ accel->insert( "Print2", Key_P, this, TQ_SLOT(slotPrint()));
+ accel->insert( "New2", Key_N, this, TQ_SLOT(slotGrab()));
+ accel->insert( "New3", Key_Space, this, TQ_SLOT(slotGrab()));
setEscapeButton( User1 );
- connect( this, TQT_SIGNAL( user1Clicked() ), TQT_SLOT( reject() ) );
+ connect( this, TQ_SIGNAL( user1Clicked() ), TQ_SLOT( reject() ) );
mainWidget->btnNew->setFocus();
+
+ oldWinPos = pos();
}
KSnapshot::~KSnapshot()
{
}
-void KSnapshot::resizeEvent( TQResizeEvent *event)
+void KSnapshot::resizeEvent( TQResizeEvent * /*event*/)
{
- if( !updateTimer.isActive() )
- updateTimer.start(200, true);
- else
- updateTimer.changeInterval(200);
+ if( !updateTimer.isActive() )
+ updateTimer.start(200, true);
+ else
+ updateTimer.changeInterval(200);
}
bool KSnapshot::save( const TQString &filename )
@@ -163,7 +216,7 @@ bool KSnapshot::save( const KURL& url )
if ( TDEIO::NetAccess::exists( url, false, this ) ) {
const TQString title = i18n( "File Exists" );
const TQString text = i18n( "<qt>Do you really want to overwrite <b>%1</b>?</qt>" ).arg(url.prettyURL());
- if (KMessageBox::Continue != KMessageBox::warningContinueCancel( this, text, title, i18n("Overwrite") ) )
+ if (KMessageBox::Continue != KMessageBox::warningContinueCancel( this, text, title, i18n("Overwrite") ) )
{
return false;
}
@@ -171,36 +224,40 @@ bool KSnapshot::save( const KURL& url )
TQString type( KImageIO::type(url.path()) );
if ( type.isNull() )
- type = "PNG";
+ type = "PNG";
bool ok = false;
if ( url.isLocalFile() ) {
- KSaveFile saveFile( url.path() );
- if ( saveFile.status() == 0 ) {
- if ( snapshot.save( saveFile.file(), type.latin1() ) )
- ok = saveFile.close();
- }
+ KSaveFile saveFile( url.path() );
+ if ( saveFile.status() == 0 ) {
+ if ( snapshot.save( saveFile.file(), type.latin1() ) ) {
+ ok = saveFile.close();
+ if (ok) {
+ setLocalFilePath(saveFile.name());
+ }
+ }
+ }
}
else {
- KTempFile tmpFile;
+ KTempFile tmpFile;
tmpFile.setAutoDelete( true );
- if ( tmpFile.status() == 0 ) {
- if ( snapshot.save( tmpFile.file(), type.latin1() ) ) {
- if ( tmpFile.close() )
- ok = TDEIO::NetAccess::upload( tmpFile.name(), url, this );
- }
- }
+ if ( tmpFile.status() == 0 ) {
+ if ( snapshot.save( tmpFile.file(), type.latin1() ) ) {
+ if ( tmpFile.close() )
+ ok = TDEIO::NetAccess::upload( tmpFile.name(), url, this );
+ }
+ }
}
TQApplication::restoreOverrideCursor();
if ( !ok ) {
- kdWarning() << "KSnapshot was unable to save the snapshot" << endl;
+ kdWarning() << "KSnapshot was unable to save the snapshot" << endl;
- TQString caption = i18n("Unable to save image");
- TQString text = i18n("KSnapshot was unable to save the image to\n%1.")
- .arg(url.prettyURL());
- KMessageBox::error(this, text, caption);
+ TQString caption = i18n("Unable to save image");
+ TQString text = i18n("KSnapshot was unable to save the image to\n%1.")
+ .arg(url.prettyURL());
+ KMessageBox::error(this, text, caption);
}
return ok;
@@ -247,27 +304,28 @@ void KSnapshot::slotCopy()
void KSnapshot::slotDragSnapshot()
{
- TQDragObject *drobj = new TQImageDrag(snapshot.convertToImage(), this);
+ TQDragObject *drobj = new SnapshotDrag(snapshot.convertToImage(), this);
drobj->setPixmap(mainWidget->preview());
drobj->dragCopy();
}
void KSnapshot::slotGrab()
{
+ oldWinPos = pos();
hide();
- if ( mainWidget->delay() && mainWidget->mode() != Region )
- grabTimer.start( mainWidget->delay() * 1000, true );
+ if ( mainWidget->delay() )
+ grabTimer.start( mainWidget->delay() * 1000, true );
else {
- if ( mainWidget->mode() == Region ) {
- rgnGrab = new RegionGrabber();
- connect( rgnGrab, TQT_SIGNAL( regionGrabbed( const TQPixmap & ) ),
- TQT_SLOT( slotRegionGrabbed( const TQPixmap & ) ) );
- }
- else {
- grabber->show();
- grabber->grabMouse( crossCursor );
- }
+ if ( mainWidget->mode() == Region ) {
+ rgnGrab = new RegionGrabber();
+ connect( rgnGrab, TQ_SIGNAL( regionGrabbed( const TQPixmap & ) ),
+ TQ_SLOT( slotRegionGrabbed( const TQPixmap & ) ) );
+ }
+ else {
+ grabber->show();
+ grabber->grabMouse( crossCursor );
+ }
}
}
@@ -283,48 +341,48 @@ void KSnapshot::slotPrint()
if (printer.setup(this, i18n("Print Screenshot")))
{
- tqApp->processEvents();
+ tqApp->processEvents();
TQPainter painter(&printer);
TQPaintDeviceMetrics metrics(painter.device());
- float w = snapshot.width();
- float dw = w - metrics.width();
- float h = snapshot.height();
- float dh = h - metrics.height();
- bool scale = false;
+ float w = snapshot.width();
+ float dw = w - metrics.width();
+ float h = snapshot.height();
+ float dh = h - metrics.height();
+ bool scale = false;
- if ( (dw > 0.0) || (dh > 0.0) )
- scale = true;
+ if ( (dw > 0.0) || (dh > 0.0) )
+ scale = true;
- if ( scale ) {
+ if ( scale ) {
- TQImage img = snapshot.convertToImage();
- tqApp->processEvents();
+ TQImage img = snapshot.convertToImage();
+ tqApp->processEvents();
- float newh, neww;
- if ( dw > dh ) {
- neww = w-dw;
- newh = neww/w*h;
- }
- else {
- newh = h-dh;
- neww = newh/h*w;
- }
+ float newh, neww;
+ if ( dw > dh ) {
+ neww = w-dw;
+ newh = neww/w*h;
+ }
+ else {
+ newh = h-dh;
+ neww = newh/h*w;
+ }
- img = img.smoothScale( int(neww), int(newh), TQ_ScaleMin );
- tqApp->processEvents();
+ img = img.smoothScale( int(neww), int(newh), TQImage::ScaleMin );
+ tqApp->processEvents();
- int x = (metrics.width()-img.width())/2;
- int y = (metrics.height()-img.height())/2;
+ int x = (metrics.width()-img.width())/2;
+ int y = (metrics.height()-img.height())/2;
- painter.drawImage( x, y, img);
- }
- else {
- int x = (metrics.width()-snapshot.width())/2;
- int y = (metrics.height()-snapshot.height())/2;
- painter.drawPixmap( x, y, snapshot );
- }
+ painter.drawImage( x, y, img);
+ }
+ else {
+ int x = (metrics.width()-snapshot.width())/2;
+ int y = (metrics.height()-snapshot.height())/2;
+ painter.drawPixmap( x, y, snapshot );
+ }
}
tqApp->processEvents();
@@ -332,35 +390,151 @@ void KSnapshot::slotPrint()
void KSnapshot::slotRegionGrabbed( const TQPixmap &pix )
{
- if ( !pix.isNull() )
- {
- snapshot = pix;
- updatePreview();
- modified = true;
- updateCaption();
- }
-
- delete rgnGrab;
- TQApplication::restoreOverrideCursor();
- show();
+ rgnGrab->deleteLater();
+ newSnapshot(pix);
}
-void KSnapshot::slotWindowGrabbed( const TQPixmap &pix )
+void KSnapshot::newSnapshot( const TQPixmap &pix )
{
if ( !pix.isNull() )
{
snapshot = pix;
updatePreview();
+ timestamp = TQDateTime::currentDateTime();
+ setLocalFilePath(TQString::null);
modified = true;
updateCaption();
}
TQApplication::restoreOverrideCursor();
+ move(oldWinPos);
show();
}
-void KSnapshot::closeEvent( TQCloseEvent * e )
+void KSnapshot::slotOpenWith(int id)
+{
+ openWithExternalApp(*openWithOffers[id]);
+}
+
+void KSnapshot::slotOpenWithKP() {
+ KService::Ptr kpaint = KService::serviceByDesktopName("kolourpaint");
+ if (kpaint) {
+ openWithExternalApp(*kpaint);
+ }
+}
+
+/// Writes the snapshot to a temporary file
+TQString KSnapshot::saveTempFile() {
+
+ // construct a pretty name for the temporary file
+ TQString base_fname =
+ i18n("A temporary filename; prefer dashes (-) as word separators if required", "snapshot")
+ .append(timestamp.toString("-yyyyMMdd-hhmmss"));
+ TQString base_fpath = locateLocal("tmp", base_fname);
+ TQString fname = base_fpath + ".png";
+
+ // We want the pretty names; unfortunately KTempFile forces us to use mkstemp-style name; which
+ // has a random string at the end, which is quite ugly. On the other hand TQFile doesn't
+ // provide any means to fail if file already exist (i.e. O_EXCL). So in order to have best of
+ // both worlds we will have to try to open the file manually and if it fails, we will fallback
+ // to KTempFile.
+ int fd = -1;
+ ExitGuard closeGuard { [&fd](){ if (fd>=0) { ::close(fd); } } };
+
+ std::unique_ptr<KTempFile> tmpFile; // used only if manual open() fails
+ std::unique_ptr<TQFile> tqfile; // used only if manual open() succeeds
+ TQFile* file; // either tqfile or tmpFile->file()
+
+ fd = KDE_open(TQFile::encodeName(fname), O_WRONLY | O_CREAT | O_EXCL, 0600);
+
+ if (fd>=0) {
+ tqfile = std::unique_ptr<TQFile>(new TQFile(fname));
+ tqfile->open( IO_WriteOnly, fd ); // according to docs TQFile won't close the fd so there is
+ // an exit guard above
+ file = tqfile.get();
+
+ } else {
+ tmpFile = std::unique_ptr<KTempFile>(new KTempFile(base_fpath + "-", ".png"));
+ if (!tmpFile || tmpFile->status() != 0) {
+ return TQString::null;
+ }
+ file = tmpFile->file();
+ fname = tmpFile->name();
+ }
+
+ // Actually save the image
+ bool ok = snapshot.save(file, "PNG");
+
+ if (!ok) {
+ file->remove();
+ return TQString::null;
+ }
+
+ tempFiles.append(fname);
+
+ return fname;
+}
+
+void KSnapshot::setLocalFilePath(TQString fp) {
+ localFilePath = fp;
+ if(!fp.isEmpty()) {
+ TQFileInfo fi(fp);
+ currentFilePathTimestamp = fi.lastModified ();
+ } else {
+ currentFilePathTimestamp = TQDateTime();
+ }
+}
+
+/// Returns a local file for the current snapshot. It may be either a file explicitly saved by the
+/// user or a temporary one saved internally
+TQString KSnapshot::localFile() {
+ bool needSaveTemp = true;
+ if(!localFilePath.isEmpty()) {
+ TQFileInfo fi(localFilePath);
+ // Checks that nobody have overwritten the file since we saved it
+ if( fi.exists() && currentFilePathTimestamp == fi.lastModified()) {
+ needSaveTemp = false;
+ }
+ }
+
+ if(needSaveTemp) {
+ setLocalFilePath( saveTempFile() );
+ }
+
+ return localFilePath;
+}
+
+void KSnapshot::openWithExternalApp(const KService &service) {
+ // Write snapshot to temporary file
+ TQString file = localFile();
+
+ if (file.isEmpty()) {
+ KMessageBox::error(this, i18n("KSnapshot was unable to create temporary file."),
+ i18n("Unable to save image"));
+ return;
+ }
+
+ // Launch application
+ KURL::List list;
+ list.append(file);
+ TQStringList args = KRun::processDesktopExec(service, list, false, false);
+
+ TDEProcess *externalApp = new TDEProcess;
+ *externalApp << args;
+
+ if (!externalApp->start(TDEProcess::OwnGroup)) {
+ KMessageBox::error(this, i18n("Cannot start %1!").arg(service.name()));
+ }
+}
+
+void KSnapshot::slotAboutToQuit()
{
+ for(const TQString &file: tempFiles)
+ {
+ TQFile::remove(file);
+ }
+ tempFiles.clear();
+
TDEConfig *conf=TDEGlobal::config();
conf->setGroup("GENERAL");
conf->writeEntry("delay",mainWidget->delay());
@@ -369,17 +543,21 @@ void KSnapshot::closeEvent( TQCloseEvent * e )
KURL url = filename;
url.setPass( TQString() );
conf->writePathEntry("filename",url.url());
+}
+
+void KSnapshot::closeEvent( TQCloseEvent * e )
+{
e->accept();
}
bool KSnapshot::eventFilter( TQObject* o, TQEvent* e)
{
- if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(grabber) && e->type() == TQEvent::MouseButtonPress ) {
- TQMouseEvent* me = (TQMouseEvent*) e;
- if ( TQWidget::mouseGrabber() != grabber )
- return false;
- if ( me->button() == Qt::LeftButton )
- performGrab();
+ if ( o == grabber && e->type() == TQEvent::MouseButtonPress ) {
+ TQMouseEvent* me = (TQMouseEvent*) e;
+ if ( TQWidget::mouseGrabber() != grabber )
+ return false;
+ if ( me->button() == TQt::LeftButton )
+ performGrab();
}
return false;
}
@@ -397,10 +575,10 @@ void KSnapshot::autoincFilename()
if (start != -1) {
// It has a number, increment it
int len = numSearch.matchedLength();
- TQString numAsStr= name.mid(start, len);
- TQString number = TQString::number(numAsStr.toInt() + 1);
- number = number.rightJustify( len, '0');
- name.replace(start, len, number );
+ TQString numAsStr= name.mid(start, len);
+ TQString number = TQString::number(numAsStr.toInt() + 1);
+ number = number.rightJustify( len, '0');
+ name.replace(start, len, number );
}
else {
// no number
@@ -415,7 +593,7 @@ void KSnapshot::autoincFilename()
}
}
- //Rebuild the path
+ // Rebuild the path
KURL newURL = filename;
newURL.setFileName( name );
setURL( newURL.url() );
@@ -430,11 +608,11 @@ void KSnapshot::grabTimerDone()
{
if ( mainWidget->mode() == Region ) {
rgnGrab = new RegionGrabber();
- connect( rgnGrab, TQT_SIGNAL( regionGrabbed( const TQPixmap & ) ),
- TQT_SLOT( slotRegionGrabbed( const TQPixmap & ) ) );
+ connect( rgnGrab, TQ_SIGNAL( regionGrabbed( const TQPixmap & ) ),
+ TQ_SLOT( slotRegionGrabbed( const TQPixmap & ) ) );
}
else {
- performGrab();
+ performGrab();
}
KNotifyClient::beep(i18n("The screen has been successfully grabbed."));
}
@@ -445,22 +623,22 @@ void KSnapshot::performGrab()
grabber->hide();
grabTimer.stop();
if ( mainWidget->mode() == ChildWindow ) {
- WindowGrabber wndGrab;
- connect( &wndGrab, TQT_SIGNAL( windowGrabbed( const TQPixmap & ) ),
- TQT_SLOT( slotWindowGrabbed( const TQPixmap & ) ) );
- wndGrab.exec();
- }
- else if ( mainWidget->mode() == WindowUnderCursor ) {
- snapshot = WindowGrabber::grabCurrent( mainWidget->includeDecorations() );
+ WindowGrabber wndGrab;
+ connect( &wndGrab, TQ_SIGNAL( windowGrabbed( const TQPixmap & ) ),
+ TQ_SLOT( newSnapshot( const TQPixmap & ) ) );
+ wndGrab.exec();
}
else {
- snapshot = TQPixmap::grabWindow( tqt_xrootwin() );
+ TQPixmap pix;
+ if ( mainWidget->mode() == WindowUnderCursor ) {
+ pix = WindowGrabber::grabCurrent( mainWidget->includeDecorations() );
+ }
+ else {
+ pix = TQPixmap::grabWindow( tqt_xrootwin() );
+ }
+
+ newSnapshot(pix);
}
- updatePreview();
- TQApplication::restoreOverrideCursor();
- modified = true;
- updateCaption();
- show();
}
void KSnapshot::setTime(int newTime)
@@ -477,12 +655,19 @@ void KSnapshot::setURL( const TQString &url )
{
KURL newURL = KURL::fromPathOrURL( url );
if ( newURL == filename )
- return;
+ return;
filename = newURL;
updateCaption();
}
+void KSnapshot::setPixmap(const TQPixmap &newImage) {
+ snapshot = newImage;
+ timestamp = TQDateTime::currentDateTime();
+ setLocalFilePath(TQString::null);
+ updatePreview();
+}
+
void KSnapshot::setGrabMode( int m )
{
mainWidget->setMode( m );
@@ -495,7 +680,7 @@ int KSnapshot::grabMode()
void KSnapshot::updateCaption()
{
- setCaption( kApp->makeStdCaption( filename.fileName(), true, modified ) );
+ setCaption( tdeApp->makeStdCaption( filename.fileName(), true, modified ) );
}
void KSnapshot::slotMovePointer(int x, int y)
@@ -507,4 +692,41 @@ void KSnapshot::exit()
{
reject();
}
+
+SnapshotDrag::SnapshotDrag( TQImage image, KSnapshot * dragSource, const char * name )
+ :TQImageDrag::TQImageDrag( image, dragSource, name ), ksnap(dragSource)
+{
+ // TQ*Drop API is a bit quirky, so to append our value to the list of formats we will have
+ // to iterate over the full list provided by TQImageDrag manually just to determine how many
+ // formats it supports
+
+ for (int i=0 ; ; i++) {
+ const char* format = TQImageDrag::format(i);
+ if (format) {
+ formats.append(format);
+ } else {
+ break;
+ }
+ }
+ formats.append("text/uri-list");
+}
+
+const char * SnapshotDrag::format(int i) const
+{
+ if( i < (int) formats.count() ) {
+ return formats[i];
+ } else {
+ return 0;
+ }
+}
+
+TQByteArray SnapshotDrag::encodedData(const char* format) const
+{
+ if( strcmp(format, "text/uri-list") == 0 ) {
+ return TQUriDrag::localFileToUri( ksnap->localFile() );
+ } else {
+ return TQImageDrag::encodedData(format);
+ }
+}
+
#include "ksnapshot.moc"
diff --git a/ksnapshot/ksnapshot.desktop b/ksnapshot/ksnapshot.desktop
index ccb90035..d5d33676 100644
--- a/ksnapshot/ksnapshot.desktop
+++ b/ksnapshot/ksnapshot.desktop
@@ -1,89 +1,10 @@
[Desktop Entry]
GenericName=Screen Capture Program
-GenericName[af]=Skerm Vang Program
-GenericName[ar]=برنامج تصوير الشاشة
-GenericName[bg]=Снимки на екрана
-GenericName[bs]=Program za "hvatanje" slike
-GenericName[ca]=Programa de captura de pantalla
-GenericName[cs]=Snímač obrazovky
-GenericName[cy]=Rhaglen Cipio'r Sgrîn
-GenericName[da]=Program til øjebliksbilleder
-GenericName[de]=Bildschirmphotos
-GenericName[el]=Πρόγραμμα σύλληψης οθόνης
-GenericName[eo]=Ekranfota programo
-GenericName[es]=Capturador de pantalla
-GenericName[et]=Töölaua pildistamine
-GenericName[eu]=Pantailari argazkiak ateratzeko programa
-GenericName[fa]=برنامۀ گیراندازی پرده
-GenericName[fi]=Ruudunkaappausohjelma
-GenericName[fr]=Logiciel de capture d'écran
-GenericName[ga]=Clár gabhála scáileáin
-GenericName[gl]=Progama para facer capturas de pantalla
-GenericName[he]=תוכנית לצילום המסך
-GenericName[hi]=स्क्रीन केप्चर प्रोग्राम
-GenericName[hr]=Program za snimanje zaslona
-GenericName[hu]=Képlopó
-GenericName[is]=Forrit sem grípur skjámyndir
-GenericName[it]=Scatta foto allo schermo
-GenericName[ja]=スクリーンキャプチャプログラム
-GenericName[kk]=Экраннан түсіріп алу бағдарламасы
-GenericName[km]=កម្មវិធី​ចាប់យក​អេក្រង់
-GenericName[lt]=Ekrano kopijos programa
-GenericName[lv]=Ekrāna Sagrābšanas Programma
-GenericName[ms]=Program Cekupan Skrin
-GenericName[mt]=Programm biex tieħu "ritratt" tal-iskrin
-GenericName[nb]=Skjermdumpprogram
-GenericName[nds]=Schirmfotos opnehmen
-GenericName[ne]=पर्दा समात्ने कार्यक्रम
-GenericName[nl]=Schermafdrukprogramma
-GenericName[nn]=Program for skjermbilete
-GenericName[nso]=Lenaneo lago Apesa Pontsho
-GenericName[pl]=Program do zrzutów ekranu
-GenericName[pt]=Programa de Captura do Ecrã
-GenericName[pt_BR]=Programa de Captura de Tela
-GenericName[ro]=Program de captură de ecran
-GenericName[ru]=Создание снимков экрана
-GenericName[rw]=Porogaramu Gufata Mugaragaza
-GenericName[se]=Šearbmagovvenprográmma
-GenericName[sk]=Zachytenie obrazovky
-GenericName[sl]=Program za zajem zaslona
-GenericName[sr]=Програм за снимање екрана
-GenericName[sr@Latn]=Program za snimanje ekrana
-GenericName[sv]=Ta en skärmdump
-GenericName[ta]=திரை கைப்பற்றும் நிரலி
-GenericName[tg]=Эҷоди суратҳои экран
-GenericName[th]=โปรแกรมจับภาพหน้าจอ
-GenericName[tr]=Ekran Yakalama Programı
-GenericName[uk]=Захоплювач екрана
-GenericName[uz]=Skrinshot olish dasturi
-GenericName[uz@cyrillic]=Скриншот олиш дастури
-GenericName[ven]=Mbekanya mushumo ino gavha tshikirini
-GenericName[wa]=Programe po fé des waitroûlêyes
-GenericName[xh]=Iinkcazelo Ezigcina Ikhusi
-GenericName[zh_CN]=屏幕截图程序
-GenericName[zh_HK]=螢幕擷取程式
-GenericName[zh_TW]=畫面擷取程式
-GenericName[zu]=Iprogremu Yokubamba Isikrini
+
Name=KSnapshot
-Name[af]=K-kiekie
-Name[cy]=KCipluniau
-Name[eo]=Ekranfotilo
-Name[fr]=KSnapShot
-Name[hi]=के-स्नेपशॉट
-Name[lv]=KSnapšots
-Name[ne]=केडीई स्न्यापसट
-Name[pl]=Zrzuty ekranu
-Name[sv]=Ksnapshot
-Name[ta]=கேதிரையை நகலெடுத்தல்
-Name[th]=จับภาพ - K
-Name[ven]=Tshinepe tsha K
-Name[wa]=KWaitroûlêye
-Name[zh_TW]=KSnapshot 快照
-Name[zu]=KEsincane isithombe
-MimeType=
+
Exec=ksnapshot -caption "%c" %i %m
Icon=ksnapshot
-Path=
Type=Application
Terminal=false
X-DocPath=ksnapshot/index.html
diff --git a/ksnapshot/ksnapshot.h b/ksnapshot/ksnapshot.h
index 5db7c0e6..45734f88 100644
--- a/ksnapshot/ksnapshot.h
+++ b/ksnapshot/ksnapshot.h
@@ -1,11 +1,11 @@
-// -*- c++ -*-
-
#ifndef KSNAPSHOT_H
#define KSNAPSHOT_H
#include "ksnapshotiface.h"
#include <tqbitmap.h>
#include <tqcursor.h>
+#include <tqdatetime.h>
+#include <tqdragobject.h>
#include <tqlabel.h>
#include <tqpainter.h>
#include <tqpixmap.h>
@@ -16,14 +16,16 @@
#include <tdeglobalsettings.h>
#include <kdialogbase.h>
#include <kurl.h>
+#include <ktrader.h>
class RegionGrabber;
class KSnapshotWidget;
+class KTempFile;
+class TDEProcess;
class KSnapshotPreview : public TQLabel
{
- Q_OBJECT
-
+ TQ_OBJECT
public:
KSnapshotPreview(TQWidget *parent, const char *name = 0)
@@ -44,14 +46,14 @@ class KSnapshotPreview : public TQLabel
{
TQPainter p(&mask);
- style().tqdrawPrimitive(TQStyle::PE_SizeGrip, &p, TQRect(0, 0, 15, 15), palette().active());
+ style().drawPrimitive(TQStyle::PE_SizeGrip, &p, TQRect(0, 0, 15, 15), palette().active());
p.end();
handle.setMask(mask);
}
{
TQPainter p(&handle);
- style().tqdrawPrimitive(TQStyle::PE_SizeGrip, &p, TQRect(0, 0, 15, 15), palette().active());
+ style().drawPrimitive(TQStyle::PE_SizeGrip, &p, TQRect(0, 0, 15, 15), palette().active());
p.end();
}
@@ -91,8 +93,7 @@ class KSnapshotPreview : public TQLabel
class KSnapshot : public KDialogBase, virtual public KSnapshotIface
{
- Q_OBJECT
-
+ TQ_OBJECT
public:
KSnapshot(TQWidget *parent= 0, const char *name= 0, bool grabCurrent=false);
@@ -102,18 +103,23 @@ public:
bool save( const TQString &filename );
TQString url() const { return filename.url(); }
+ TQString localFile();
protected slots:
+ void slotAboutToQuit();
void slotGrab();
void slotSave();
void slotSaveAs();
void slotCopy();
void slotPrint();
+ void slotOpenWith(int id);
+ void slotOpenWithKP();
void slotMovePointer( int x, int y );
void setTime(int newTime);
void setURL(const TQString &newURL);
void setGrabMode( int m );
+ void setPixmap(const TQPixmap &newImage);
void exit();
protected:
@@ -122,21 +128,24 @@ protected:
virtual void closeEvent( TQCloseEvent * e );
void resizeEvent(TQResizeEvent*);
bool eventFilter( TQObject*, TQEvent* );
-
+
private slots:
void grabTimerDone();
void slotDragSnapshot();
void updateCaption();
void updatePreview();
void slotRegionGrabbed( const TQPixmap & );
- void slotWindowGrabbed( const TQPixmap & );
+ void newSnapshot( const TQPixmap & );
private:
bool save( const KURL& url );
+ void openWithExternalApp(const KService &service);
void performGrab();
void autoincFilename();
int grabMode();
int timeout();
+ TQString saveTempFile();
+ void setLocalFilePath(TQString fp);
TQPixmap snapshot;
TQTimer grabTimer;
@@ -145,7 +154,28 @@ private:
KURL filename;
KSnapshotWidget *mainWidget;
RegionGrabber *rgnGrab;
+ TQDateTime timestamp;
bool modified;
+ TDETrader::OfferList openWithOffers;
+ TQString localFilePath;
+ TQDateTime currentFilePathTimestamp;
+ TQValueList<TQString> tempFiles;
+ TQPoint oldWinPos;
+};
+
+
+/**
+ * A small wrapper around TQImageDrag that also passes text/uri-list with a
+ * temporary file as a fallback variant.
+ */
+class SnapshotDrag : public TQImageDrag {
+ TQ_OBJECT
+ KSnapshot *ksnap;
+ TQValueList<TQCString> formats;
+public:
+ SnapshotDrag( TQImage image, KSnapshot * dragSource, const char * name = 0 );
+ const char * format(int i) const;
+ TQByteArray encodedData(const char* format) const;
};
#endif // KSNAPSHOT_H
diff --git a/ksnapshot/ksnapshotiface.h b/ksnapshot/ksnapshotiface.h
index 5136b0ba..e8ac5158 100644
--- a/ksnapshot/ksnapshotiface.h
+++ b/ksnapshot/ksnapshotiface.h
@@ -12,6 +12,7 @@
#define __KS_IFACE_H
#include <dcopobject.h>
+#include <tqpixmap.h>
class KSnapshotIface : virtual public DCOPObject
{
@@ -60,6 +61,10 @@ class KSnapshotIface : virtual public DCOPObject
/** Exit KSnapshot **/
virtual void exit() = 0;
+
+ /** Set image, for applications which want to make use of KSnapshot's UI
+ and interface with their own images */
+ virtual void setPixmap(const TQPixmap &newImage) = 0;
};
#endif
diff --git a/ksnapshot/ksnapshotwidget.ui b/ksnapshot/ksnapshotwidget.ui
index 245d433b..71385f90 100644
--- a/ksnapshot/ksnapshotwidget.ui
+++ b/ksnapshot/ksnapshotwidget.ui
@@ -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>
@@ -290,6 +318,12 @@ If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click b
<slot>slotPrintClicked()</slot>
</connection>
<connection>
+ <sender>btnOpenWithKP</sender>
+ <signal>clicked()</signal>
+ <receiver>KSnapshotWidget</receiver>
+ <slot>slotOpenWithKPClicked()</slot>
+ </connection>
+ <connection>
<sender>btnSave</sender>
<signal>clicked()</signal>
<receiver>KSnapshotWidget</receiver>
@@ -323,23 +357,25 @@ If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click b
<include location="global" impldecl="in implementation">tdeglobalsettings.h</include>
<include location="local" impldecl="in implementation">ksnapshotwidget.ui.h</include>
</includes>
-<Q_SIGNALS>
+<signals>
<signal>newClicked()</signal>
<signal>saveClicked()</signal>
<signal>copyClicked()</signal>
<signal>printClicked()</signal>
+ <signal>openWithKPClicked()</signal>
<signal>startImageDrag()</signal>
-</Q_SIGNALS>
-<Q_SLOTS>
+</signals>
+<slots>
<slot access="protected" specifier="non virtual">slotModeChanged( int mode )</slot>
<slot access="protected" specifier="non virtual">slotNewClicked()</slot>
<slot access="protected" specifier="non virtual">slotSaveClicked()</slot>
<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>
+</slots>
<functions>
<function specifier="non virtual">setPreview( const TQPixmap &amp; pm )</function>
<function specifier="non virtual">setDelay( int i )</function>
diff --git a/ksnapshot/ksnapshotwidget.ui.h b/ksnapshot/ksnapshotwidget.ui.h
index 921accc9..c84f65ca 100644
--- a/ksnapshot/ksnapshotwidget.ui.h
+++ b/ksnapshot/ksnapshotwidget.ui.h
@@ -27,8 +27,6 @@ void KSnapshotWidget::slotModeChanged( int mode )
default:
break;
}
-
- spinDelay->setEnabled(mode != 2);
}
@@ -39,10 +37,10 @@ void KSnapshotWidget::setPreview( const TQPixmap &pm )
if ( r1 * previewWidth() < previewHeight() )
img = img.smoothScale( previewWidth(),
int( previewWidth() * r1 ),
- TQ_ScaleMin );
+ TQImage::ScaleMin );
else
img = img.smoothScale( ( int ) ( ( ( double )previewHeight() ) / r1 ),
- previewHeight(), TQ_ScaleMin );
+ previewHeight(), TQImage::ScaleMin );
TQToolTip::remove( lblImage );
TQToolTip::add( lblImage,
@@ -136,3 +134,8 @@ void KSnapshotWidget::slotCopyClicked()
{
emit copyClicked();
}
+
+void KSnapshotWidget::slotOpenWithKPClicked()
+{
+ emit openWithKPClicked();
+}
diff --git a/ksnapshot/regiongrabber.cpp b/ksnapshot/regiongrabber.cpp
index 2c4d4a2b..a562fdcc 100644
--- a/ksnapshot/regiongrabber.cpp
+++ b/ksnapshot/regiongrabber.cpp
@@ -74,9 +74,9 @@ RegionGrabber::RegionGrabber()
sizeTip = new SizeTip( ( TQWidget * )0L );
tipTimer = new TQTimer( this );
- connect( tipTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( updateSizeTip() ) );
+ connect( tipTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( updateSizeTip() ) );
- TQTimer::singleShot( 200, this, TQT_SLOT( initGrabber() ) );
+ TQTimer::singleShot( 200, this, TQ_SLOT( initGrabber() ) );
}
RegionGrabber::~RegionGrabber()
@@ -104,7 +104,7 @@ void RegionGrabber::initGrabber()
void RegionGrabber::mousePressEvent( TQMouseEvent *e )
{
- if ( e->button() == Qt::LeftButton )
+ if ( e->button() == TQt::LeftButton )
{
mouseDown = true;
grabRect = TQRect( e->pos(), e->pos() );
@@ -168,7 +168,7 @@ void RegionGrabber::drawRubber()
p.setPen( TQPen( color0, 1 ) );
p.setBrush( NoBrush );
- style().tqdrawPrimitive( TQStyle::PE_FocusRect, &p, grabRect, colorGroup(),
+ style().drawPrimitive( TQStyle::PE_FocusRect, &p, grabRect, colorGroup(),
TQStyle::Style_Default, TQStyleOption( colorGroup().base() ) );
p.end();
diff --git a/ksnapshot/regiongrabber.h b/ksnapshot/regiongrabber.h
index 24c65d70..0495bf5a 100644
--- a/ksnapshot/regiongrabber.h
+++ b/ksnapshot/regiongrabber.h
@@ -37,7 +37,7 @@ class SizeTip : public TQLabel
class RegionGrabber : public TQWidget
{
- Q_OBJECT
+ TQ_OBJECT
public:
diff --git a/ksnapshot/windowgrabber.cpp b/ksnapshot/windowgrabber.cpp
index eac0fa6e..70fbabdc 100644
--- a/ksnapshot/windowgrabber.cpp
+++ b/ksnapshot/windowgrabber.cpp
@@ -240,7 +240,7 @@ TQPixmap WindowGrabber::grabCurrent( bool includeDecorations )
void WindowGrabber::mousePressEvent( TQMouseEvent *e )
{
- if ( e->button() == Qt::RightButton )
+ if ( e->button() == TQt::RightButton )
yPos = e->globalY();
else {
TQPixmap pm;
@@ -258,7 +258,7 @@ void WindowGrabber::mousePressEvent( TQMouseEvent *e )
void WindowGrabber::mouseReleaseEvent( TQMouseEvent *e )
{
- if ( e->button() == Qt::RightButton )
+ if ( e->button() == TQt::RightButton )
yPos = -1;
}
diff --git a/ksnapshot/windowgrabber.h b/ksnapshot/windowgrabber.h
index cf2c186a..eb771d8d 100644
--- a/ksnapshot/windowgrabber.h
+++ b/ksnapshot/windowgrabber.h
@@ -28,7 +28,7 @@
class WindowGrabber : public TQDialog
{
- Q_OBJECT
+ TQ_OBJECT
public: