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