summaryrefslogtreecommitdiff
authorsandman <sandman>2002-12-30 04:49:31 (UTC)
committer sandman <sandman>2002-12-30 04:49:31 (UTC)
commit597ebce95168c56dbfdec4a79b11a4b793bdd351 (patch) (unidiff)
tree390dc4ccc6eacbe472cd5e4610f21921940ad73d
parent67391742b90744379da532fc41e6229660e40df6 (diff)
downloadopie-597ebce95168c56dbfdec4a79b11a4b793bdd351.zip
opie-597ebce95168c56dbfdec4a79b11a4b793bdd351.tar.gz
opie-597ebce95168c56dbfdec4a79b11a4b793bdd351.tar.bz2
- rewrote the SCAP part (doesn't need netcat anymore now)
- cleaned up the code - reworked the GUI a bit
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/screenshotapplet/screenshot.cpp411
-rw-r--r--core/applets/screenshotapplet/screenshot.h28
2 files changed, 228 insertions, 211 deletions
diff --git a/core/applets/screenshotapplet/screenshot.cpp b/core/applets/screenshotapplet/screenshot.cpp
index 266d6d8..fab4044 100644
--- a/core/applets/screenshotapplet/screenshot.cpp
+++ b/core/applets/screenshotapplet/screenshot.cpp
@@ -17,7 +17,10 @@
17 17
18#include <qapplication.h> 18#include <qapplication.h>
19#include <stdlib.h> 19#include <stdlib.h>
20 20#include <sys/socket.h>
21#include <netinet/in.h>
22#include <netdb.h>
23#include <unistd.h>
21 24
22#include <qpe/resource.h> 25#include <qpe/resource.h>
23#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
@@ -26,12 +29,11 @@
26#include <qpe/config.h> 29#include <qpe/config.h>
27#include <qpe/applnk.h> 30#include <qpe/applnk.h>
28#include <qpe/config.h> 31#include <qpe/config.h>
29#include <qsocket.h>
30 32
31#include <qlineedit.h> 33#include <qlineedit.h>
32#include <qdir.h> 34#include <qdir.h>
33#include <qfileinfo.h> 35#include <qfileinfo.h>
34#include <qpoint.h> 36#include <qlabel.h>
35#include <qpushbutton.h> 37#include <qpushbutton.h>
36#include <qpainter.h> 38#include <qpainter.h>
37#include <qcombobox.h> 39#include <qcombobox.h>
@@ -47,6 +49,7 @@
47#include <qfile.h> 49#include <qfile.h>
48#include <qdatastream.h> 50#include <qdatastream.h>
49#include <qcheckbox.h> 51#include <qcheckbox.h>
52#include <qmessagebox.h>
50 53
51 54
52static char * snapshot_xpm[] = { 55static char * snapshot_xpm[] = {
@@ -78,231 +81,257 @@ static char * snapshot_xpm[] = {
78" .. ", 81" .. ",
79" "}; 82" "};
80 83
84static const char *SCAP_hostname = "www.handhelds.org";
85static const int SCAP_port = 80;
86
81 87
82ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name ) 88ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name )
83 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 89 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
84{ 90{
85 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 91 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
86// qDebug("screenshot control"); 92 QVBoxLayout *vbox = new QVBoxLayout ( this, 5, 3 );
87 QVBoxLayout *vbox = new QVBoxLayout( this ); 93 QHBoxLayout *hbox;
88 QHBoxLayout *hbox = new QHBoxLayout( this );
89// qDebug("new layout");
90 delaySpin = new QSpinBox( 0,60,1, this, "Spinner" );
91// qDebug("new spinbox");
92 delaySpin->setFocusPolicy( QWidget::NoFocus );
93
94
95 grabItButton= new QPushButton( this, "GrabButton" );
96// qDebug("new pushbutton");
97
98 grabItButton ->setFocusPolicy( QWidget::TabFocus );
99 grabItButton->setText(tr("Snapshot"));
100 94
95 hbox = new QHBoxLayout ( vbox );
101 96
102 vbox->setMargin( 6 ); 97 QLabel *l = new QLabel ( tr( "Delay" ), this );
103 vbox->setSpacing( 3 ); 98 hbox-> addWidget ( l );
104 99
105 vbox->addWidget( delaySpin); 100 delaySpin = new QSpinBox( 0, 60, 1, this, "Spinner" );
101 delaySpin-> setButtonSymbols ( QSpinBox::PlusMinus );
102 delaySpin-> setSuffix ( tr( "sec" ));
103 delaySpin-> setFocusPolicy( QWidget::NoFocus );
104 delaySpin-> setValue ( 1 );
105 hbox-> addWidget ( delaySpin );
106 106
107 vbox->setMargin( 6 ); 107 saveNamedCheck = new QCheckBox ( tr( "Save named" ), this);
108 vbox->setSpacing( 3 ); 108 saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus );
109 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); 109 vbox->addWidget( saveNamedCheck);
110 vbox->addItem( spacer );
111 110
112 saveNamedCheck= new QCheckBox ( "name it", this); 111 vbox-> addSpacing ( 3 );
113 saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus );
114 vbox->addWidget( saveNamedCheck);
115 112
113 l = new QLabel ( tr( "Save screenshot as..." ), this );
114 vbox-> addWidget ( l, AlignCenter );
116 115
117 scapButton = new QPushButton( this, "ScapButton" ); 116 hbox = new QHBoxLayout ( vbox );
118 117
119 scapButton ->setFocusPolicy( QWidget::TabFocus ); 118 grabItButton = new QPushButton( tr( "File" ), this, "GrabButton" );
120 scapButton ->setText(tr("scap")); 119 grabItButton ->setFocusPolicy( QWidget::TabFocus );
121 if( !QFile("/usr/bin/nc").exists()) 120 hbox-> addWidget ( grabItButton );
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 121
129 vbox->addItem(hbox); 122 scapButton = new QPushButton( tr( "Scap" ), this, "ScapButton" );
123 scapButton ->setFocusPolicy( QWidget::TabFocus );
124 hbox-> addWidget ( scapButton );
130 125
131 setFixedHeight( 100 ); 126 setFixedSize ( sizeHint ( ));
132 setFixedWidth( sizeHint().width() ); 127 setFocusPolicy ( QWidget::NoFocus );
133 setFocusPolicy(QWidget::NoFocus);
134 128
135 grabTimer= new QTimer(this,"grab timer");
136 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) );
137 129
138 delaySpin->setValue(1); 130 grabTimer = new QTimer ( this, "grab timer");
139 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) ); 131
140 connect( scapButton, SIGNAL(released()), SLOT(slotScap()) ); 132 connect ( grabTimer, SIGNAL( timeout ( )), this, SLOT( performGrab ( )));
141 connect(saveNamedCheck, SIGNAL(toggled( bool)), this, SLOT( nameScreenshot(bool)) ); 133 connect ( grabItButton, SIGNAL( clicked ( )), SLOT( slotGrab ( )));
134 connect ( scapButton, SIGNAL( clicked ( )), SLOT( slotScap ( )));
142} 135}
143 136
144void ScreenshotControl::slotGrab() { 137void ScreenshotControl::slotGrab()
145// qDebug("SlotGrab"); 138{
146 buttonPushed=1; 139 buttonPushed = 1;
147 hide(); 140 hide();
148 setFileName=FALSE; 141
149 if( saveNamedCheck->isChecked()) { 142 setFileName = FALSE;
150 setFileName=TRUE; 143 if ( saveNamedCheck->isChecked()) {
151// qDebug("checked"); 144 setFileName = TRUE;
152 InputDialog *fileDlg; 145 InputDialog *fileDlg;
153 146
154 fileDlg = new InputDialog( 0 ,tr("Name of screenshot "),TRUE, 0); 147 fileDlg = new InputDialog( 0 , tr("Name of screenshot "), TRUE, 0);
155 fileDlg->exec(); 148 fileDlg->exec();
156 fileDlg->raise(); 149 fileDlg->raise();
157 QString fileName,list; 150 QString fileName, list;
158 if( fileDlg->result() == 1 ) { 151 if ( fileDlg->result() == 1 ) {
159 fileName = fileDlg->LineEdit1->text(); 152 fileName = fileDlg->LineEdit1->text();
160 153
161 if(fileName.find("/",0,TRUE)==-1) 154 if (fileName.find("/", 0, TRUE) == -1)
162 FileNamePath = QDir::homeDirPath()+"/Documents/image/png/"+fileName; 155 FileNamePath = QDir::homeDirPath() + "/Documents/image/png/" + fileName;
163 else 156 else
164 FileNamePath = fileName; 157 FileNamePath = fileName;
165// qDebug(fileName); 158
166 159 }
167 } 160 delete fileDlg;
168 delete fileDlg; 161 }
169 } 162
170 if ( delaySpin->value() ) { 163 if ( delaySpin->value() )
171 grabTimer->start( delaySpin->value() * 1000, true ); 164 grabTimer->start( delaySpin->value() * 1000, true );
172 } else { 165 else
173 show(); 166 show();
174 }
175}
176
177void ScreenshotControl::slotScap() {
178 buttonPushed=2;
179 hide();
180 if ( delaySpin->value() ) {
181 grabTimer->start( delaySpin->value() * 1000, true );
182 } else {
183 show();
184 }
185} 167}
186 168
169void ScreenshotControl::slotScap()
170{
171 buttonPushed = 2;
172 hide();
187 173
188void ScreenshotControl::grabTimerDone() { 174 if ( delaySpin->value() )
189 performGrab(); 175 grabTimer->start( delaySpin->value() * 1000, true );
176 else
177 show();
190} 178}
191 179
192void ScreenshotControl::savePixmap() {
193 DocLnk lnk;
194 QString fileName;
195
196 if( setFileName) {
197 fileName=FileNamePath;
198//not sure why this is needed here, but it forgets fileName
199 // if this is below the braces
200
201 if(fileName.right(3)!="png")
202 fileName=fileName+".png";
203 lnk.setFile(fileName); //sets File property
204 qDebug("saving file "+fileName);
205 snapshot.save( fileName,"PNG");
206 QFileInfo fi( fileName);
207 lnk.setName( fi.fileName()); //sets file name
208
209 if(!lnk.writeLink())
210 qDebug("Writing doclink did not work");
211 } else {
212
213 fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true);
214 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),"");
215 QString dirName = QDir::homeDirPath()+"/Documents/image/png/";
216
217 if( !QDir( dirName).exists() ) {
218 qDebug("making dir "+dirName);
219 QString msg = "mkdir -p "+dirName;
220 system(msg.latin1());
221 }
222 fileName=dirName+fileName;
223 if(fileName.right(3)!="png")
224 fileName=fileName+".png";
225 lnk.setFile(fileName); //sets File property
226 qDebug("saving file "+fileName);
227 snapshot.save( fileName,"PNG");
228 QFileInfo fi( fileName);
229 lnk.setName( fi.fileName()); //sets file name
230
231 if(!lnk.writeLink())
232 qDebug("Writing doclink did not work");
233
234 }
235
236 QPEApplication::beep();
237}
238 180
239void ScreenshotControl::performGrab() { 181void ScreenshotControl::savePixmap()
240 182{
241 if(buttonPushed ==1) { 183 DocLnk lnk;
242 qDebug("grabbing screen"); 184 QString fileName;
243 grabTimer->stop(); 185
244 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() ); 186 if ( setFileName) {
245 show(); 187 fileName = FileNamePath;
246 qApp->processEvents(); 188 //not sure why this is needed here, but it forgets fileName
247 savePixmap(); 189 // if this is below the braces
248 } else { 190
249 qDebug("scap"); 191 if (fileName.right(3) != "png")
250 grabTimer->stop(); 192 fileName = fileName + ".png";
251// do scap here 193 lnk.setFile(fileName); //sets File property
252 QString cmd; 194 qDebug("saving file " + fileName);
253 cmd="cat /dev/fd0 > /tmp/cap"; 195 snapshot.save( fileName, "PNG");
254 system(cmd.latin1()); 196 QFileInfo fi( fileName);
255// qDebug("echo \"POST /scap/capture.cgi http1.1\" 197 lnk.setName( fi.fileName()); //sets file name
256// echo \"Content-length: 153600\" 198
257// echo \"Content-Type: image/gif\" 199 if (!lnk.writeLink())
258// echo \"HOST: www.handhelds.org\" 200 qDebug("Writing doclink did not work");
259// echo \"\" 201 }
260// cat /tmp/cap | nc h1.handhelds.org 80"); 202 else {
261 cmd="nc h1.handhelds.org 1011 </tmp/cap"; 203
262 qDebug("running command "+cmd); 204 fileName = "sc_" + TimeString::dateString( QDateTime::currentDateTime(), false, true);
263 205 fileName.replace(QRegExp("'"), "");
264 system(cmd.latin1()); 206 fileName.replace(QRegExp(" "), "_");
265 show(); 207 fileName.replace(QRegExp(":"), ".");
266 } 208 fileName.replace(QRegExp(","), "");
267 209 QString dirName = QDir::homeDirPath() + "/Documents/image/png/";
210
211 if ( !QDir( dirName).exists() ) {
212 qDebug("making dir " + dirName);
213 QString msg = "mkdir -p " + dirName;
214 system(msg.latin1());
215 }
216 fileName = dirName + fileName;
217 if (fileName.right(3) != "png")
218 fileName = fileName + ".png";
219 lnk.setFile(fileName); //sets File property
220 qDebug("saving file " + fileName);
221 snapshot.save( fileName, "PNG");
222 QFileInfo fi( fileName);
223 lnk.setName( fi.fileName()); //sets file name
224
225 if (!lnk.writeLink())
226 qDebug("Writing doclink did not work");
227
228 }
229
230 QPEApplication::beep();
268} 231}
269 232
270void ScreenshotControl::setTime(int newTime) { 233void ScreenshotControl::performGrab()
271 delaySpin->setValue(newTime); 234{
235 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(), 0, 0, QApplication::desktop()->width(), QApplication::desktop()->height() );
236
237 if (buttonPushed == 1) {
238 qDebug("grabbing screen");
239 grabTimer->stop();
240 show();
241 qApp->processEvents();
242 savePixmap();
243 }
244 else {
245 grabTimer->stop();
246
247 struct sockaddr_in raddr;
248 struct hostent *rhost_info;
249 int sock = -1;
250 bool ok = false;
251
252 if (( rhost_info = (struct hostent *) ::gethostbyname ((char *) SCAP_hostname )) != 0 ) {
253 ::memset ( &raddr, 0, sizeof (struct sockaddr_in));
254 ::memcpy ( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length );
255 raddr. sin_family = rhost_info-> h_addrtype;
256 raddr. sin_port = htons ( SCAP_port );
257
258 if (( sock = ::socket ( AF_INET, SOCK_STREAM, 0 )) >= 0 )
259 {
260 if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) {
261 QString header;
262
263 header = "POST /scap/capture.cgi?%1+%2 HTTP/1.1\n" // 1: model / 2: user
264 "Content-length: 153600\n"
265 "Content-Type: image/gif\n"
266 "Host: %4\n" // 3: scap host
267 "\n";
268
269 header = header. arg ( "" ). arg ( ::getenv ( "USER" )). arg ( SCAP_hostname );
270
271 QPixmap pix;
272
273 if ( snapshot. width ( ) == 320 && snapshot. height ( ) == 240 )
274 {
275 pix = snapshot;
276 }
277 else if ( snapshot. width ( ) == 240 && snapshot. height ( ) == 320 )
278 {
279 pix = snapshot. xForm ( QWMatrix ( ). rotate ( 90 ));
280 }
281
282 if ( !pix. isNull ( ))
283 {
284 const char *ascii = header. latin1 ( );
285 uint ascii_len = ::strlen ( ascii );
286
287 ::write ( sock, ascii, ascii_len );
288
289 QImage img = pix. convertToImage ( ). convertDepth ( 16 );
290 ::write ( sock, img. bits ( ), img.numBytes ( ));
291
292 ok = true;
293 }
294 }
295 ::close ( sock );
296 }
297 }
298 if ( ok )
299 QMessageBox::information ( 0, tr( "Success" ), QString ( "<p>%1</p>" ). arg ( tr( "Screenshot was uploaded to %1" )). arg ( SCAP_hostname ));
300 else
301 QMessageBox::warning ( 0, tr( "Error" ), QString ( "<p>%1</p>" ). arg ( tr( "Connection to %1 failed." )). arg ( SCAP_hostname ));
302 }
303
272} 304}
273 305
274void ScreenshotControl::nameScreenshot(bool b) {
275 306
276
277}
278 307
279//=========================================================================== 308//===========================================================================
280 309
281ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) 310ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name )
282 : QWidget( parent, name ) { 311 : QWidget( parent, name )
283// qDebug("beginning applet"); 312{
284 setFixedHeight( 18 ); 313 setFixedHeight( 18 );
285 setFixedWidth( 14 ); 314 setFixedWidth( 14 );
286 vc = new ScreenshotControl(this,"ScreenshotApplet");; 315
287// qDebug("new screenshotapplet"); 316 m_icon = QPixmap ((const char **) snapshot_xpm );
288} 317}
289 318
290ScreenshotApplet::~ScreenshotApplet() { 319ScreenshotApplet::~ScreenshotApplet()
320{
291} 321}
292 322
293void ScreenshotApplet::mousePressEvent( QMouseEvent *) { 323void ScreenshotApplet::mousePressEvent( QMouseEvent *)
294// if(!vc) 324{
295 vc = new ScreenshotControl; 325 ScreenshotControl *sc = new ScreenshotControl ( );
296 QPoint curPos = mapToGlobal( rect().topLeft() ); 326 QPoint curPos = mapToGlobal ( QPoint ( 0, 0 ));
297 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); 327 sc-> move ( curPos. x ( ) - ( sc-> sizeHint ( ). width ( ) - width ( )) / 2,
298 vc->show(); 328 curPos. y ( ) - sc-> sizeHint ( ). height ( ));
299 329 sc-> show ( );
300} 330}
301 331
302void ScreenshotApplet::paintEvent( QPaintEvent* ) { 332void ScreenshotApplet::paintEvent( QPaintEvent* )
303 QPainter p(this); 333{
304 qDebug("paint pixmap"); 334 QPainter p ( this );
305 p.drawPixmap( 0, 1, ( const char** ) snapshot_xpm ); 335 p. drawPixmap ( 0, 1, m_icon );
306
307} 336}
308 337
diff --git a/core/applets/screenshotapplet/screenshot.h b/core/applets/screenshotapplet/screenshot.h
index c8dfeaa..74cc5e6 100644
--- a/core/applets/screenshotapplet/screenshot.h
+++ b/core/applets/screenshotapplet/screenshot.h
@@ -34,47 +34,35 @@ class ScreenshotControl : public QFrame
34 Q_OBJECT 34 Q_OBJECT
35public: 35public:
36 ScreenshotControl( QWidget *parent=0, const char *name=0 ); 36 ScreenshotControl( QWidget *parent=0, const char *name=0 );
37 void performGrab();
38 37
39public: 38private:
40 QPushButton *grabItButton, *scapButton; 39 QPushButton *grabItButton, *scapButton;
41 QPixmap snapshot; 40 QPixmap snapshot;
42 QTimer* grabTimer; 41 QTimer* grabTimer;
43 QCheckBox *saveNamedCheck; 42 QCheckBox *saveNamedCheck;
44 QString FileNamePath; 43 QString FileNamePath;
45 bool setFileName; 44 bool setFileName;
46 void slotSave();
47 void slotCopy();
48 void setTime(int newTime);
49
50 QSpinBox *delaySpin; 45 QSpinBox *delaySpin;
51private:
52 int buttonPushed; 46 int buttonPushed;
47
53private slots: 48private slots:
54 void slotGrab(); 49 void slotGrab();
55 void slotScap(); 50 void slotScap();
56 void savePixmap(); 51 void savePixmap();
57 void grabTimerDone(); 52 void performGrab();
58 void nameScreenshot(bool);
59}; 53};
60 54
61class ScreenshotApplet : public QWidget 55class ScreenshotApplet : public QWidget {
62{
63 Q_OBJECT
64public: 56public:
65 ScreenshotApplet( QWidget *parent = 0, const char *name=0 ); 57 ScreenshotApplet( QWidget *parent = 0, const char *name=0 );
66 ~ScreenshotApplet(); 58 ~ScreenshotApplet();
67 ScreenshotControl *vc; 59
68public slots: 60protected:
69private:
70 void mousePressEvent( QMouseEvent * ); 61 void mousePressEvent( QMouseEvent * );
71 void paintEvent( QPaintEvent* ); 62 void paintEvent( QPaintEvent* );
72 63
73private: 64private:
74 QPixmap snapshotPixmap; 65 QPixmap m_icon;
75private slots:
76
77
78}; 66};
79 67
80 68