|
|
|
@ -36,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>
|
|
|
|
@ -60,8 +63,6 @@
|
|
|
|
|
|
|
|
|
|
#define kApp TDEApplication::kApplication()
|
|
|
|
|
|
|
|
|
|
#define KOLOURPAINT_EXE "/opt/trinity/bin/kolourpaint"
|
|
|
|
|
|
|
|
|
|
KSnapshot::KSnapshot(TQWidget *parent, const char *name, bool grabCurrent)
|
|
|
|
|
: DCOPObject("interface"),
|
|
|
|
|
KDialogBase(parent, name, true, TQString(), Help|User1, User1,
|
|
|
|
@ -82,7 +83,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( openKolourPaint() ), TQT_SLOT( slotOpenKolourPaint() ) );
|
|
|
|
|
connect( mainWidget, TQT_SIGNAL( openWithKPClicked() ), TQT_SLOT( slotOpenWithKP() ) );
|
|
|
|
|
|
|
|
|
|
grabber->show();
|
|
|
|
|
grabber->grabMouse( waitCursor );
|
|
|
|
@ -120,6 +121,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..."),
|
|
|
|
@ -364,22 +383,27 @@ void KSnapshot::slotWindowGrabbed( const TQPixmap &pix )
|
|
|
|
|
show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KSnapshot::slotOpenKolourPaint()
|
|
|
|
|
void KSnapshot::slotOpenWith(int id)
|
|
|
|
|
{
|
|
|
|
|
slotCopy();
|
|
|
|
|
openWithExternalApp(*openWithOffers[id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TQFileInfo kolourPaintExeFile( KOLOURPAINT_EXE );
|
|
|
|
|
if (!kolourPaintExeFile.exists())
|
|
|
|
|
{
|
|
|
|
|
tqWarning( "koulourpaint executable was not found\nMake sure the executable is in the default location");
|
|
|
|
|
void KSnapshot::slotOpenWithKP() {
|
|
|
|
|
KService::Ptr kpaint = KService::serviceByDesktopName("kolourpaint");
|
|
|
|
|
if (kpaint) {
|
|
|
|
|
openWithExternalApp(*kpaint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static KTempFile *tmpFile = nullptr;
|
|
|
|
|
|
|
|
|
|
// Write to temporary file
|
|
|
|
|
void KSnapshot::openWithExternalApp(const KService &service) {
|
|
|
|
|
// Write snapshot to temporary file
|
|
|
|
|
bool ok = false;
|
|
|
|
|
KTempFile tmpFile;
|
|
|
|
|
if (tmpFile.status() == 0) {
|
|
|
|
|
if (snapshot.save(tmpFile.file(), "PNG")) {
|
|
|
|
|
if (tmpFile.close()) {
|
|
|
|
|
tmpFile = new KTempFile;
|
|
|
|
|
if (tmpFile->status() == 0) {
|
|
|
|
|
if (snapshot.save(tmpFile->file(), "PNG")) {
|
|
|
|
|
if (tmpFile->close()) {
|
|
|
|
|
ok = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -392,28 +416,28 @@ void KSnapshot::slotOpenKolourPaint()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Launch KolourPaint
|
|
|
|
|
TDEProcess *kpaint = new TDEProcess;
|
|
|
|
|
*kpaint << kolourPaintExeFile.filePath();
|
|
|
|
|
*kpaint << tmpFile.name();
|
|
|
|
|
if (!kpaint->start(TDEProcess::OwnGroup)) {
|
|
|
|
|
KMessageBox::error(this, i18n("Cannot start KolourPaint!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Launch application
|
|
|
|
|
KURL::List list;
|
|
|
|
|
list.append(tmpFile->name());
|
|
|
|
|
TQStringList args = KRun::processDesktopExec(service, list, false, false);
|
|
|
|
|
|
|
|
|
|
// Update screenshot when KolourPaint is closed
|
|
|
|
|
connect(kpaint, SIGNAL(processExited(TDEProcess*)),
|
|
|
|
|
this, SLOT(slotKolourPaintClosed(TDEProcess*)));
|
|
|
|
|
}
|
|
|
|
|
TDEProcess *externalApp = new TDEProcess;
|
|
|
|
|
*externalApp << args;
|
|
|
|
|
connect(externalApp, SIGNAL(processExited(TDEProcess*)),
|
|
|
|
|
this, SLOT(slotExternalAppClosed()));
|
|
|
|
|
|
|
|
|
|
void KSnapshot::slotKolourPaintClosed(TDEProcess *kpaint) {
|
|
|
|
|
TQFile tmpFile(kpaint->args()[1]);
|
|
|
|
|
if (!tmpFile.exists()) {
|
|
|
|
|
if (!externalApp->start(TDEProcess::OwnGroup)) {
|
|
|
|
|
KMessageBox::error(this, i18n("Cannot start %1!").arg(service.name()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
snapshot.load(tmpFile.name());
|
|
|
|
|
tmpFile.remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KSnapshot::slotExternalAppClosed() {
|
|
|
|
|
snapshot.load(tmpFile->name());
|
|
|
|
|
updatePreview();
|
|
|
|
|
tmpFile->unlink();
|
|
|
|
|
delete tmpFile;
|
|
|
|
|
tmpFile = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KSnapshot::closeEvent( TQCloseEvent * e )
|
|
|
|
|