summaryrefslogtreecommitdiff
path: root/core/applets/screenshotapplet/screenshot.cpp
Unidiff
Diffstat (limited to 'core/applets/screenshotapplet/screenshot.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/screenshotapplet/screenshot.cpp201
1 files changed, 154 insertions, 47 deletions
diff --git a/core/applets/screenshotapplet/screenshot.cpp b/core/applets/screenshotapplet/screenshot.cpp
index 8a2a956..4ebdb7a 100644
--- a/core/applets/screenshotapplet/screenshot.cpp
+++ b/core/applets/screenshotapplet/screenshot.cpp
@@ -15,2 +15,4 @@
15#include "screenshot.h" 15#include "screenshot.h"
16#include "inputDialog.h"
17
16#include <qapplication.h> 18#include <qapplication.h>
@@ -26,3 +28,5 @@
26#include <qpe/config.h> 28#include <qpe/config.h>
29#include <qsocket.h>
27 30
31#include <qlineedit.h>
28#include <qdir.h> 32#include <qdir.h>
@@ -42,2 +46,6 @@
42#include <qtimer.h> 46#include <qtimer.h>
47#include <qfile.h>
48#include <qdatastream.h>
49#include <qcheckbox.h>
50
43 51
@@ -79,2 +87,3 @@ ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name )
79 QVBoxLayout *vbox = new QVBoxLayout( this ); 87 QVBoxLayout *vbox = new QVBoxLayout( this );
88 QHBoxLayout *hbox = new QHBoxLayout( this );
80// qDebug("new layout"); 89// qDebug("new layout");
@@ -83,12 +92,39 @@ ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name )
83 delaySpin->setFocusPolicy( QWidget::NoFocus ); 92 delaySpin->setFocusPolicy( QWidget::NoFocus );
93
94
84 grabItButton= new QPushButton( this, "GrabButton" ); 95 grabItButton= new QPushButton( this, "GrabButton" );
85// qDebug("new pushbutton"); 96// qDebug("new pushbutton");
97
86 grabItButton ->setFocusPolicy( QWidget::TabFocus ); 98 grabItButton ->setFocusPolicy( QWidget::TabFocus );
87 grabItButton->setText(tr("Snapshot")); 99 grabItButton->setText(tr("Snapshot"));
100
101
88 vbox->setMargin( 6 ); 102 vbox->setMargin( 6 );
89 vbox->setSpacing( 3 ); 103 vbox->setSpacing( 3 );
104
90 vbox->addWidget( delaySpin); 105 vbox->addWidget( delaySpin);
106
91 vbox->setMargin( 6 ); 107 vbox->setMargin( 6 );
92 vbox->setSpacing( 3 ); 108 vbox->setSpacing( 3 );
93 vbox->addWidget( grabItButton); 109 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
110 vbox->addItem( spacer );
111
112 saveNamedCheck= new QCheckBox ( "name it", this);
113 saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus );
114 vbox->addWidget( saveNamedCheck);
115
116
117 scapButton = new QPushButton( this, "ScapButton" );
118
119 scapButton ->setFocusPolicy( QWidget::TabFocus );
120 scapButton ->setText(tr("scap"));
121 if( !QFile("/usr/bin/nc").exists())
122 scapButton->hide();
123
124 hbox->addWidget( grabItButton);
125 QSpacerItem* spacer2 = new QSpacerItem( 4, 4, QSizePolicy::Minimum, QSizePolicy::Expanding );
126 hbox->addItem( spacer2 );
127 hbox->addWidget( scapButton);
128
129 vbox->addItem(hbox);
94 130
@@ -99,16 +135,43 @@ ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name )
99 grabTimer= new QTimer(this,"grab timer"); 135 grabTimer= new QTimer(this,"grab timer");
100// qDebug("newTimer");
101 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) ); 136 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) );
102 137
103// Config cfg("Snapshot"); 138 delaySpin->setValue(1);
104// cfg.setGroup("General");
105 delaySpin->setValue(1);
106// delaySpin->setValue(cfg.readNumEntry("delay",0));
107 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) ); 139 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) );
108 140 connect( scapButton, SIGNAL(released()), SLOT(slotScap()) );
141 connect(saveNamedCheck, SIGNAL(toggled( bool)), this, SLOT( nameScreenshot(bool)) );
109} 142}
110 143
111void ScreenshotControl::slotGrab() 144void ScreenshotControl::slotGrab() {
112{
113// qDebug("SlotGrab"); 145// qDebug("SlotGrab");
146 buttonPushed=1;
147 hide();
148 setFileName=FALSE;
149 if( saveNamedCheck->isChecked()) {
150 setFileName=TRUE;
151// qDebug("checked");
152 InputDialog *fileDlg;
153
154 fileDlg = new InputDialog( 0 ,tr("Name of screenshot "),TRUE, 0);
155 fileDlg->exec();
156 fileDlg->raise();
157 QString fileName,list;
158 if( fileDlg->result() == 1 ) {
159 fileName = fileDlg->LineEdit1->text();
160
161 if(fileName.find("/",0,TRUE)==-1)
162 FileNamePath = QDir::homeDirPath()+"/Documents/image/png/"+fileName;
163// qDebug(fileName);
164
165 }
166 delete fileDlg;
167 }
168 if ( delaySpin->value() ) {
169 grabTimer->start( delaySpin->value() * 1000, true );
170 } else {
171 show();
172 }
173}
174
175void ScreenshotControl::slotScap() {
176 buttonPushed=2;
114 hide(); 177 hide();
@@ -122,4 +185,3 @@ void ScreenshotControl::slotGrab()
122 185
123void ScreenshotControl::grabTimerDone() 186void ScreenshotControl::grabTimerDone() {
124{
125 performGrab(); 187 performGrab();
@@ -127,38 +189,81 @@ void ScreenshotControl::grabTimerDone()
127 189
128void ScreenshotControl::savePixmap() 190void ScreenshotControl::savePixmap() {
129{
130 DocLnk lnk; 191 DocLnk lnk;
131 QString fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true); 192 QString fileName;
132 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),""); 193
133 194 if( setFileName) {
134 QString dirName = QDir::homeDirPath()+"/Documents/image/png/"; 195 fileName=FileNamePath;
135 if( !QDir( dirName).exists() ) { 196//not sure why this is needed here, but it forgets fileName
136 qDebug("making dir "+dirName); 197 // if this is below the braces
137 QString msg = "mkdir -p "+dirName; 198
138 system(msg.latin1()); 199 if(fileName.right(3)!="png")
200 fileName=fileName+".png";
201 lnk.setFile(fileName); //sets File property
202 qDebug("saving file "+fileName);
203 snapshot.save( fileName,"PNG");
204 QFileInfo fi( fileName);
205 lnk.setName( fi.fileName()); //sets file name
206
207 if(!lnk.writeLink())
208 qDebug("Writing doclink did not work");
209 } else {
210
211 fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true);
212 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),"");
213 QString dirName = QDir::homeDirPath()+"/Documents/image/png/";
214
215 if( !QDir( dirName).exists() ) {
216 qDebug("making dir "+dirName);
217 QString msg = "mkdir -p "+dirName;
218 system(msg.latin1());
219 }
220 fileName=dirName+fileName;
221 if(fileName.right(3)!="png")
222 fileName=fileName+".png";
223 lnk.setFile(fileName); //sets File property
224 qDebug("saving file "+fileName);
225 snapshot.save( fileName,"PNG");
226 QFileInfo fi( fileName);
227 lnk.setName( fi.fileName()); //sets file name
228
229 if(!lnk.writeLink())
230 qDebug("Writing doclink did not work");
231
139 } 232 }
140 fileName=dirName+fileName+".png";
141 lnk.setFile(fileName); //sets File property
142 snapshot.save( fileName,"PNG");
143 qDebug("saving file "+fileName);
144 QFileInfo fi( fileName);
145 lnk.setName( fi.fileName()); //sets file name
146 if(!lnk.writeLink())
147 qDebug("Writing doclink did not work");
148 233
149 QPEApplication::beep(); 234 QPEApplication::beep();
150
151} 235}
152 236
153void ScreenshotControl::performGrab() 237void ScreenshotControl::performGrab() {
154{ 238
155 qDebug("grabbing screen"); 239 if(buttonPushed ==1) {
156 grabTimer->stop(); 240 qDebug("grabbing screen");
157 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() ); 241 grabTimer->stop();
158 show(); 242 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() );
159 savePixmap(); 243 show();
244 qApp->processEvents();
245 savePixmap();
246 } else {
247 qDebug("scap");
248 grabTimer->stop();
249// do scap here
250 QString cmd;
251 cmd="cat /dev/fd0 > /tmp/cap";
252 system(cmd.latin1());
253// qDebug("echo \"POST /scap/capture.cgi http1.1\"
254// echo \"Content-length: 153600\"
255// echo \"Content-Type: image/gif\"
256// echo \"HOST: www.handhelds.org\"
257// echo \"\"
258// cat /tmp/cap | nc h1.handhelds.org 80");
259 cmd="nc h1.handhelds.org 1011 </tmp/cap";
260 qDebug("running command "+cmd);
261
262 system(cmd.latin1());
263 show();
264 }
265
160} 266}
161 267
162void ScreenshotControl::setTime(int newTime) 268void ScreenshotControl::setTime(int newTime) {
163{
164 delaySpin->setValue(newTime); 269 delaySpin->setValue(newTime);
@@ -166,2 +271,7 @@ void ScreenshotControl::setTime(int newTime)
166 271
272void ScreenshotControl::nameScreenshot(bool b) {
273
274
275}
276
167//=========================================================================== 277//===========================================================================
@@ -169,4 +279,3 @@ void ScreenshotControl::setTime(int newTime)
169ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) 279ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name )
170 : QWidget( parent, name ) 280 : QWidget( parent, name ) {
171{
172// qDebug("beginning applet"); 281// qDebug("beginning applet");
@@ -178,8 +287,6 @@ ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name )
178 287
179ScreenshotApplet::~ScreenshotApplet() 288ScreenshotApplet::~ScreenshotApplet() {
180{
181} 289}
182 290
183void ScreenshotApplet::mousePressEvent( QMouseEvent *) 291void ScreenshotApplet::mousePressEvent( QMouseEvent *) {
184{
185// if(!vc) 292// if(!vc)
@@ -192,4 +299,3 @@ void ScreenshotApplet::mousePressEvent( QMouseEvent *)
192 299
193void ScreenshotApplet::paintEvent( QPaintEvent* ) 300void ScreenshotApplet::paintEvent( QPaintEvent* ) {
194{
195 QPainter p(this); 301 QPainter p(this);
@@ -199 +305,2 @@ void ScreenshotApplet::paintEvent( QPaintEvent* )
199} 305}
306