-rw-r--r-- | core/applets/screenshotapplet/screenshot.cpp | 229 | ||||
-rw-r--r-- | core/applets/screenshotapplet/screenshot.h | 26 |
2 files changed, 136 insertions, 119 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 | ||
52 | static char * snapshot_xpm[] = { | 55 | static char * snapshot_xpm[] = { |
@@ -78,77 +81,67 @@ static char * snapshot_xpm[] = { | |||
78 | " .. ", | 81 | " .. ", |
79 | " "}; | 82 | " "}; |
80 | 83 | ||
84 | static const char *SCAP_hostname = "www.handhelds.org"; | ||
85 | static const int SCAP_port = 80; | ||
86 | |||
81 | 87 | ||
82 | ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name ) | 88 | ScreenshotControl::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 | |||
101 | 94 | ||
102 | vbox->setMargin( 6 ); | 95 | hbox = new QHBoxLayout ( vbox ); |
103 | vbox->setSpacing( 3 ); | ||
104 | 96 | ||
105 | vbox->addWidget( delaySpin); | 97 | QLabel *l = new QLabel ( tr( "Delay" ), this ); |
98 | hbox-> addWidget ( l ); | ||
106 | 99 | ||
107 | vbox->setMargin( 6 ); | 100 | delaySpin = new QSpinBox( 0, 60, 1, this, "Spinner" ); |
108 | vbox->setSpacing( 3 ); | 101 | delaySpin-> setButtonSymbols ( QSpinBox::PlusMinus ); |
109 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 102 | delaySpin-> setSuffix ( tr( "sec" )); |
110 | vbox->addItem( spacer ); | 103 | delaySpin-> setFocusPolicy( QWidget::NoFocus ); |
104 | delaySpin-> setValue ( 1 ); | ||
105 | hbox-> addWidget ( delaySpin ); | ||
111 | 106 | ||
112 | saveNamedCheck= new QCheckBox ( "name it", this); | 107 | saveNamedCheck = new QCheckBox ( tr( "Save named" ), this); |
113 | saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus ); | 108 | saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus ); |
114 | vbox->addWidget( saveNamedCheck); | 109 | vbox->addWidget( saveNamedCheck); |
115 | 110 | ||
111 | vbox-> addSpacing ( 3 ); | ||
116 | 112 | ||
117 | scapButton = new QPushButton( this, "ScapButton" ); | 113 | l = new QLabel ( tr( "Save screenshot as..." ), this ); |
114 | vbox-> addWidget ( l, AlignCenter ); | ||
118 | 115 | ||
119 | scapButton ->setFocusPolicy( QWidget::TabFocus ); | 116 | hbox = new QHBoxLayout ( vbox ); |
120 | scapButton ->setText(tr("scap")); | ||
121 | if( !QFile("/usr/bin/nc").exists()) | ||
122 | scapButton->hide(); | ||
123 | 117 | ||
118 | grabItButton = new QPushButton( tr( "File" ), this, "GrabButton" ); | ||
119 | grabItButton ->setFocusPolicy( QWidget::TabFocus ); | ||
124 | hbox->addWidget( grabItButton); | 120 | 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() ); | ||
133 | setFocusPolicy(QWidget::NoFocus); | 127 | setFocusPolicy(QWidget::NoFocus); |
134 | 128 | ||
129 | |||
135 | grabTimer= new QTimer(this,"grab timer"); | 130 | grabTimer= new QTimer(this,"grab timer"); |
136 | connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) ); | ||
137 | 131 | ||
138 | delaySpin->setValue(1); | 132 | connect ( grabTimer, SIGNAL( timeout ( )), this, SLOT( performGrab ( ))); |
139 | connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) ); | 133 | connect ( grabItButton, SIGNAL( clicked ( )), SLOT( slotGrab ( ))); |
140 | connect( scapButton, SIGNAL(released()), SLOT(slotScap()) ); | 134 | connect ( scapButton, SIGNAL( clicked ( )), SLOT( slotScap ( ))); |
141 | connect(saveNamedCheck, SIGNAL(toggled( bool)), this, SLOT( nameScreenshot(bool)) ); | ||
142 | } | 135 | } |
143 | 136 | ||
144 | void ScreenshotControl::slotGrab() { | 137 | void ScreenshotControl::slotGrab() |
145 | // qDebug("SlotGrab"); | 138 | { |
146 | buttonPushed=1; | 139 | buttonPushed=1; |
147 | hide(); | 140 | hide(); |
141 | |||
148 | setFileName=FALSE; | 142 | setFileName=FALSE; |
149 | if( saveNamedCheck->isChecked()) { | 143 | if( saveNamedCheck->isChecked()) { |
150 | setFileName=TRUE; | 144 | setFileName=TRUE; |
151 | // qDebug("checked"); | ||
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); |
@@ -162,34 +155,31 @@ void ScreenshotControl::slotGrab() { | |||
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); | ||
166 | 158 | ||
167 | } | 159 | } |
168 | delete fileDlg; | 160 | delete fileDlg; |
169 | } | 161 | } |
170 | if ( delaySpin->value() ) { | 162 | |
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 | } | 167 | } |
175 | } | ||
176 | 168 | ||
177 | void ScreenshotControl::slotScap() { | 169 | void ScreenshotControl::slotScap() |
170 | { | ||
178 | buttonPushed=2; | 171 | buttonPushed=2; |
179 | hide(); | 172 | hide(); |
180 | if ( delaySpin->value() ) { | 173 | |
174 | if ( delaySpin->value() ) | ||
181 | grabTimer->start( delaySpin->value() * 1000, true ); | 175 | grabTimer->start( delaySpin->value() * 1000, true ); |
182 | } else { | 176 | else |
183 | show(); | 177 | show(); |
184 | } | 178 | } |
185 | } | ||
186 | |||
187 | 179 | ||
188 | void ScreenshotControl::grabTimerDone() { | ||
189 | performGrab(); | ||
190 | } | ||
191 | 180 | ||
192 | void ScreenshotControl::savePixmap() { | 181 | void ScreenshotControl::savePixmap() |
182 | { | ||
193 | DocLnk lnk; | 183 | DocLnk lnk; |
194 | QString fileName; | 184 | QString fileName; |
195 | 185 | ||
@@ -208,10 +198,14 @@ void ScreenshotControl::savePixmap() { | |||
208 | 198 | ||
209 | if(!lnk.writeLink()) | 199 | if(!lnk.writeLink()) |
210 | qDebug("Writing doclink did not work"); | 200 | qDebug("Writing doclink did not work"); |
211 | } else { | 201 | } |
202 | else { | ||
212 | 203 | ||
213 | fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true); | 204 | fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true); |
214 | fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),""); | 205 | fileName.replace(QRegExp("'"), ""); |
206 | fileName.replace(QRegExp(" "), "_"); | ||
207 | fileName.replace(QRegExp(":"), "."); | ||
208 | fileName.replace(QRegExp(","), ""); | ||
215 | QString dirName = QDir::homeDirPath()+"/Documents/image/png/"; | 209 | QString dirName = QDir::homeDirPath()+"/Documents/image/png/"; |
216 | 210 | ||
217 | if( !QDir( dirName).exists() ) { | 211 | if( !QDir( dirName).exists() ) { |
@@ -236,73 +230,108 @@ void ScreenshotControl::savePixmap() { | |||
236 | QPEApplication::beep(); | 230 | QPEApplication::beep(); |
237 | } | 231 | } |
238 | 232 | ||
239 | void ScreenshotControl::performGrab() { | 233 | void ScreenshotControl::performGrab() |
234 | { | ||
235 | snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(), 0, 0, QApplication::desktop()->width(), QApplication::desktop()->height() ); | ||
240 | 236 | ||
241 | if(buttonPushed ==1) { | 237 | if(buttonPushed ==1) { |
242 | qDebug("grabbing screen"); | 238 | qDebug("grabbing screen"); |
243 | grabTimer->stop(); | 239 | grabTimer->stop(); |
244 | snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() ); | ||
245 | show(); | 240 | show(); |
246 | qApp->processEvents(); | 241 | qApp->processEvents(); |
247 | savePixmap(); | 242 | savePixmap(); |
248 | } else { | ||
249 | qDebug("scap"); | ||
250 | grabTimer->stop(); | ||
251 | // do scap here | ||
252 | QString cmd; | ||
253 | cmd="cat /dev/fd0 > /tmp/cap"; | ||
254 | system(cmd.latin1()); | ||
255 | // qDebug("echo \"POST /scap/capture.cgi http1.1\" | ||
256 | // echo \"Content-length: 153600\" | ||
257 | // echo \"Content-Type: image/gif\" | ||
258 | // echo \"HOST: www.handhelds.org\" | ||
259 | // echo \"\" | ||
260 | // cat /tmp/cap | nc h1.handhelds.org 80"); | ||
261 | cmd="nc h1.handhelds.org 1011 </tmp/cap"; | ||
262 | qDebug("running command "+cmd); | ||
263 | |||
264 | system(cmd.latin1()); | ||
265 | show(); | ||
266 | } | 243 | } |
244 | else { | ||
245 | grabTimer->stop(); | ||
267 | 246 | ||
268 | } | 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; | ||
269 | 262 | ||
270 | void ScreenshotControl::setTime(int newTime) { | 263 | header = "POST /scap/capture.cgi?%1+%2 HTTP/1.1\n" // 1: model / 2: user |
271 | delaySpin->setValue(newTime); | 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; | ||
272 | } | 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 ); | ||
273 | 286 | ||
274 | void ScreenshotControl::nameScreenshot(bool b) { | 287 | ::write ( sock, ascii, ascii_len ); |
275 | 288 | ||
289 | QImage img = pix. convertToImage ( ). convertDepth ( 16 ); | ||
290 | ::write ( sock, img. bits ( ), img.numBytes ( )); | ||
276 | 291 | ||
292 | ok = true; | ||
277 | } | 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 | |||
304 | } | ||
305 | |||
306 | |||
278 | 307 | ||
279 | //=========================================================================== | 308 | //=========================================================================== |
280 | 309 | ||
281 | ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) | 310 | ScreenshotApplet::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");; | ||
287 | // qDebug("new screenshotapplet"); | ||
288 | } | ||
289 | 315 | ||
290 | ScreenshotApplet::~ScreenshotApplet() { | 316 | m_icon = QPixmap ((const char **) snapshot_xpm ); |
291 | } | 317 | } |
292 | 318 | ||
293 | void ScreenshotApplet::mousePressEvent( QMouseEvent *) { | 319 | ScreenshotApplet::~ScreenshotApplet() |
294 | // if(!vc) | 320 | { |
295 | vc = new ScreenshotControl; | 321 | } |
296 | QPoint curPos = mapToGlobal( rect().topLeft() ); | ||
297 | vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); | ||
298 | vc->show(); | ||
299 | 322 | ||
323 | void ScreenshotApplet::mousePressEvent( QMouseEvent *) | ||
324 | { | ||
325 | ScreenshotControl *sc = new ScreenshotControl ( ); | ||
326 | QPoint curPos = mapToGlobal ( QPoint ( 0, 0 )); | ||
327 | sc-> move ( curPos. x ( ) - ( sc-> sizeHint ( ). width ( ) - width ( )) / 2, | ||
328 | curPos. y ( ) - sc-> sizeHint ( ). height ( )); | ||
329 | sc-> show ( ); | ||
300 | } | 330 | } |
301 | 331 | ||
302 | void ScreenshotApplet::paintEvent( QPaintEvent* ) { | 332 | void ScreenshotApplet::paintEvent( QPaintEvent* ) |
333 | { | ||
303 | QPainter p(this); | 334 | QPainter p(this); |
304 | qDebug("paint pixmap"); | 335 | p. drawPixmap ( 0, 1, m_icon ); |
305 | p.drawPixmap( 0, 1, ( const char** ) snapshot_xpm ); | ||
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 |
35 | public: | 35 | public: |
36 | ScreenshotControl( QWidget *parent=0, const char *name=0 ); | 36 | ScreenshotControl( QWidget *parent=0, const char *name=0 ); |
37 | void performGrab(); | ||
38 | 37 | ||
39 | public: | 38 | private: |
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; |
51 | private: | ||
52 | int buttonPushed; | 46 | int buttonPushed; |
47 | |||
53 | private slots: | 48 | private 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 | ||
61 | class ScreenshotApplet : public QWidget | 55 | class ScreenshotApplet : public QWidget { |
62 | { | ||
63 | Q_OBJECT | ||
64 | public: | 56 | public: |
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 | |
68 | public slots: | 60 | protected: |
69 | private: | ||
70 | void mousePressEvent( QMouseEvent * ); | 61 | void mousePressEvent( QMouseEvent * ); |
71 | void paintEvent( QPaintEvent* ); | 62 | void paintEvent( QPaintEvent* ); |
72 | 63 | ||
73 | private: | 64 | private: |
74 | QPixmap snapshotPixmap; | 65 | QPixmap m_icon; |
75 | private slots: | ||
76 | |||
77 | |||
78 | }; | 66 | }; |
79 | 67 | ||
80 | 68 | ||