summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-16 15:13:23 (UTC)
committer llornkcor <llornkcor>2002-11-16 15:13:23 (UTC)
commit1fde54b44ba888094fc47201567ea9454857f5a1 (patch) (unidiff)
tree955a367a304554a0adc8193a193b31c996a15bf0
parent91b18bba79406b6ff54ca7f1360035eceefee378 (diff)
downloadopie-1fde54b44ba888094fc47201567ea9454857f5a1.zip
opie-1fde54b44ba888094fc47201567ea9454857f5a1.tar.gz
opie-1fde54b44ba888094fc47201567ea9454857f5a1.tar.bz2
fix for filename paths
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/screenshotapplet/screenshot.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/core/applets/screenshotapplet/screenshot.cpp b/core/applets/screenshotapplet/screenshot.cpp
index 98f2c9e..266d6d8 100644
--- a/core/applets/screenshotapplet/screenshot.cpp
+++ b/core/applets/screenshotapplet/screenshot.cpp
@@ -1,306 +1,308 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com 2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com
3** All rights reserved. 3** All rights reserved.
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13**********************************************************************/ 13**********************************************************************/
14 14
15#include "screenshot.h" 15#include "screenshot.h"
16#include "inputDialog.h" 16#include "inputDialog.h"
17 17
18#include <qapplication.h> 18#include <qapplication.h>
19#include <stdlib.h> 19#include <stdlib.h>
20 20
21 21
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <qpe/timestring.h> 24#include <qpe/timestring.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <qpe/applnk.h> 27#include <qpe/applnk.h>
28#include <qpe/config.h> 28#include <qpe/config.h>
29#include <qsocket.h> 29#include <qsocket.h>
30 30
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qpoint.h> 34#include <qpoint.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qcombobox.h> 37#include <qcombobox.h>
38#include <qspinbox.h> 38#include <qspinbox.h>
39#include <qslider.h> 39#include <qslider.h>
40#include <qlayout.h> 40#include <qlayout.h>
41#include <qframe.h> 41#include <qframe.h>
42#include <qpixmap.h> 42#include <qpixmap.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qstring.h> 44#include <qstring.h>
45#include <qfile.h> 45#include <qfile.h>
46#include <qtimer.h> 46#include <qtimer.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdatastream.h> 48#include <qdatastream.h>
49#include <qcheckbox.h> 49#include <qcheckbox.h>
50 50
51 51
52static char * snapshot_xpm[] = { 52static char * snapshot_xpm[] = {
53"16 16 10 1", 53"16 16 10 1",
54" c None", 54" c None",
55". c #000000", 55". c #000000",
56"+ c #00C000", 56"+ c #00C000",
57"@ c #585858", 57"@ c #585858",
58"# c #808080", 58"# c #808080",
59"$ c #00FF00", 59"$ c #00FF00",
60"% c #008000", 60"% c #008000",
61"& c #00FFFF", 61"& c #00FFFF",
62"* c #FF0000", 62"* c #FF0000",
63"= c #FFC0C0", 63"= c #FFC0C0",
64" ", 64" ",
65" ... ", 65" ... ",
66" ..+++..@#. ", 66" ..+++..@#. ",
67" .$++++++.#. ", 67" .$++++++.#. ",
68" .%$$++++++. ", 68" .%$$++++++. ",
69" .&%%$$++@***. ", 69" .&%%$$++@***. ",
70" .$&$++$=**@+. ", 70" .$&$++$=**@+. ",
71" .+$$+++@*$%%. ", 71" .+$$+++@*$%%. ",
72" .+++++%+++%%. ", 72" .+++++%+++%%. ",
73" .%%++++..+%%. ", 73" .%%++++..+%%. ",
74" ..%%+++++%%. ", 74" ..%%+++++%%. ",
75" ..%%+++%%. ", 75" ..%%+++%%. ",
76" ..%%+%%. ", 76" ..%%+%%. ",
77" ..%%.. ", 77" ..%%.. ",
78" .. ", 78" .. ",
79" "}; 79" "};
80 80
81 81
82ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name ) 82ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name )
83 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 83 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
84{ 84{
85 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 85 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
86// qDebug("screenshot control"); 86// qDebug("screenshot control");
87 QVBoxLayout *vbox = new QVBoxLayout( this ); 87 QVBoxLayout *vbox = new QVBoxLayout( this );
88 QHBoxLayout *hbox = new QHBoxLayout( this ); 88 QHBoxLayout *hbox = new QHBoxLayout( this );
89// qDebug("new layout"); 89// qDebug("new layout");
90 delaySpin = new QSpinBox( 0,60,1, this, "Spinner" ); 90 delaySpin = new QSpinBox( 0,60,1, this, "Spinner" );
91// qDebug("new spinbox"); 91// qDebug("new spinbox");
92 delaySpin->setFocusPolicy( QWidget::NoFocus ); 92 delaySpin->setFocusPolicy( QWidget::NoFocus );
93 93
94 94
95 grabItButton= new QPushButton( this, "GrabButton" ); 95 grabItButton= new QPushButton( this, "GrabButton" );
96// qDebug("new pushbutton"); 96// qDebug("new pushbutton");
97 97
98 grabItButton ->setFocusPolicy( QWidget::TabFocus ); 98 grabItButton ->setFocusPolicy( QWidget::TabFocus );
99 grabItButton->setText(tr("Snapshot")); 99 grabItButton->setText(tr("Snapshot"));
100 100
101 101
102 vbox->setMargin( 6 ); 102 vbox->setMargin( 6 );
103 vbox->setSpacing( 3 ); 103 vbox->setSpacing( 3 );
104 104
105 vbox->addWidget( delaySpin); 105 vbox->addWidget( delaySpin);
106 106
107 vbox->setMargin( 6 ); 107 vbox->setMargin( 6 );
108 vbox->setSpacing( 3 ); 108 vbox->setSpacing( 3 );
109 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); 109 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
110 vbox->addItem( spacer ); 110 vbox->addItem( spacer );
111 111
112 saveNamedCheck= new QCheckBox ( "name it", this); 112 saveNamedCheck= new QCheckBox ( "name it", this);
113 saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus ); 113 saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus );
114 vbox->addWidget( saveNamedCheck); 114 vbox->addWidget( saveNamedCheck);
115 115
116 116
117 scapButton = new QPushButton( this, "ScapButton" ); 117 scapButton = new QPushButton( this, "ScapButton" );
118 118
119 scapButton ->setFocusPolicy( QWidget::TabFocus ); 119 scapButton ->setFocusPolicy( QWidget::TabFocus );
120 scapButton ->setText(tr("scap")); 120 scapButton ->setText(tr("scap"));
121 if( !QFile("/usr/bin/nc").exists()) 121 if( !QFile("/usr/bin/nc").exists())
122 scapButton->hide(); 122 scapButton->hide();
123 123
124 hbox->addWidget( grabItButton); 124 hbox->addWidget( grabItButton);
125 QSpacerItem* spacer2 = new QSpacerItem( 4, 4, QSizePolicy::Minimum, QSizePolicy::Expanding ); 125 QSpacerItem* spacer2 = new QSpacerItem( 4, 4, QSizePolicy::Minimum, QSizePolicy::Expanding );
126 hbox->addItem( spacer2 ); 126 hbox->addItem( spacer2 );
127 hbox->addWidget( scapButton); 127 hbox->addWidget( scapButton);
128 128
129 vbox->addItem(hbox); 129 vbox->addItem(hbox);
130 130
131 setFixedHeight( 100 ); 131 setFixedHeight( 100 );
132 setFixedWidth( sizeHint().width() ); 132 setFixedWidth( sizeHint().width() );
133 setFocusPolicy(QWidget::NoFocus); 133 setFocusPolicy(QWidget::NoFocus);
134 134
135 grabTimer= new QTimer(this,"grab timer"); 135 grabTimer= new QTimer(this,"grab timer");
136 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) ); 136 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) );
137 137
138 delaySpin->setValue(1); 138 delaySpin->setValue(1);
139 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) ); 139 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) );
140 connect( scapButton, SIGNAL(released()), SLOT(slotScap()) ); 140 connect( scapButton, SIGNAL(released()), SLOT(slotScap()) );
141 connect(saveNamedCheck, SIGNAL(toggled( bool)), this, SLOT( nameScreenshot(bool)) ); 141 connect(saveNamedCheck, SIGNAL(toggled( bool)), this, SLOT( nameScreenshot(bool)) );
142} 142}
143 143
144void ScreenshotControl::slotGrab() { 144void ScreenshotControl::slotGrab() {
145// qDebug("SlotGrab"); 145// qDebug("SlotGrab");
146 buttonPushed=1; 146 buttonPushed=1;
147 hide(); 147 hide();
148 setFileName=FALSE; 148 setFileName=FALSE;
149 if( saveNamedCheck->isChecked()) { 149 if( saveNamedCheck->isChecked()) {
150 setFileName=TRUE; 150 setFileName=TRUE;
151// qDebug("checked"); 151// qDebug("checked");
152 InputDialog *fileDlg; 152 InputDialog *fileDlg;
153 153
154 fileDlg = new InputDialog( 0 ,tr("Name of screenshot "),TRUE, 0); 154 fileDlg = new InputDialog( 0 ,tr("Name of screenshot "),TRUE, 0);
155 fileDlg->exec(); 155 fileDlg->exec();
156 fileDlg->raise(); 156 fileDlg->raise();
157 QString fileName,list; 157 QString fileName,list;
158 if( fileDlg->result() == 1 ) { 158 if( fileDlg->result() == 1 ) {
159 fileName = fileDlg->LineEdit1->text(); 159 fileName = fileDlg->LineEdit1->text();
160 160
161 if(fileName.find("/",0,TRUE)==-1) 161 if(fileName.find("/",0,TRUE)==-1)
162 FileNamePath = QDir::homeDirPath()+"/Documents/image/png/"+fileName; 162 FileNamePath = QDir::homeDirPath()+"/Documents/image/png/"+fileName;
163 else
164 FileNamePath = fileName;
163// qDebug(fileName); 165// qDebug(fileName);
164 166
165 } 167 }
166 delete fileDlg; 168 delete fileDlg;
167 } 169 }
168 if ( delaySpin->value() ) { 170 if ( delaySpin->value() ) {
169 grabTimer->start( delaySpin->value() * 1000, true ); 171 grabTimer->start( delaySpin->value() * 1000, true );
170 } else { 172 } else {
171 show(); 173 show();
172 } 174 }
173} 175}
174 176
175void ScreenshotControl::slotScap() { 177void ScreenshotControl::slotScap() {
176 buttonPushed=2; 178 buttonPushed=2;
177 hide(); 179 hide();
178 if ( delaySpin->value() ) { 180 if ( delaySpin->value() ) {
179 grabTimer->start( delaySpin->value() * 1000, true ); 181 grabTimer->start( delaySpin->value() * 1000, true );
180 } else { 182 } else {
181 show(); 183 show();
182 } 184 }
183} 185}
184 186
185 187
186void ScreenshotControl::grabTimerDone() { 188void ScreenshotControl::grabTimerDone() {
187 performGrab(); 189 performGrab();
188} 190}
189 191
190void ScreenshotControl::savePixmap() { 192void ScreenshotControl::savePixmap() {
191 DocLnk lnk; 193 DocLnk lnk;
192 QString fileName; 194 QString fileName;
193 195
194 if( setFileName) { 196 if( setFileName) {
195 fileName=FileNamePath; 197 fileName=FileNamePath;
196//not sure why this is needed here, but it forgets fileName 198//not sure why this is needed here, but it forgets fileName
197 // if this is below the braces 199 // if this is below the braces
198 200
199 if(fileName.right(3)!="png") 201 if(fileName.right(3)!="png")
200 fileName=fileName+".png"; 202 fileName=fileName+".png";
201 lnk.setFile(fileName); //sets File property 203 lnk.setFile(fileName); //sets File property
202 qDebug("saving file "+fileName); 204 qDebug("saving file "+fileName);
203 snapshot.save( fileName,"PNG"); 205 snapshot.save( fileName,"PNG");
204 QFileInfo fi( fileName); 206 QFileInfo fi( fileName);
205 lnk.setName( fi.fileName()); //sets file name 207 lnk.setName( fi.fileName()); //sets file name
206 208
207 if(!lnk.writeLink()) 209 if(!lnk.writeLink())
208 qDebug("Writing doclink did not work"); 210 qDebug("Writing doclink did not work");
209 } else { 211 } else {
210 212
211 fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true); 213 fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true);
212 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),""); 214 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),"");
213 QString dirName = QDir::homeDirPath()+"/Documents/image/png/"; 215 QString dirName = QDir::homeDirPath()+"/Documents/image/png/";
214 216
215 if( !QDir( dirName).exists() ) { 217 if( !QDir( dirName).exists() ) {
216 qDebug("making dir "+dirName); 218 qDebug("making dir "+dirName);
217 QString msg = "mkdir -p "+dirName; 219 QString msg = "mkdir -p "+dirName;
218 system(msg.latin1()); 220 system(msg.latin1());
219 } 221 }
220 fileName=dirName+fileName; 222 fileName=dirName+fileName;
221 if(fileName.right(3)!="png") 223 if(fileName.right(3)!="png")
222 fileName=fileName+".png"; 224 fileName=fileName+".png";
223 lnk.setFile(fileName); //sets File property 225 lnk.setFile(fileName); //sets File property
224 qDebug("saving file "+fileName); 226 qDebug("saving file "+fileName);
225 snapshot.save( fileName,"PNG"); 227 snapshot.save( fileName,"PNG");
226 QFileInfo fi( fileName); 228 QFileInfo fi( fileName);
227 lnk.setName( fi.fileName()); //sets file name 229 lnk.setName( fi.fileName()); //sets file name
228 230
229 if(!lnk.writeLink()) 231 if(!lnk.writeLink())
230 qDebug("Writing doclink did not work"); 232 qDebug("Writing doclink did not work");
231 233
232 } 234 }
233 235
234 QPEApplication::beep(); 236 QPEApplication::beep();
235} 237}
236 238
237void ScreenshotControl::performGrab() { 239void ScreenshotControl::performGrab() {
238 240
239 if(buttonPushed ==1) { 241 if(buttonPushed ==1) {
240 qDebug("grabbing screen"); 242 qDebug("grabbing screen");
241 grabTimer->stop(); 243 grabTimer->stop();
242 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() ); 244 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() );
243 show(); 245 show();
244 qApp->processEvents(); 246 qApp->processEvents();
245 savePixmap(); 247 savePixmap();
246 } else { 248 } else {
247 qDebug("scap"); 249 qDebug("scap");
248 grabTimer->stop(); 250 grabTimer->stop();
249// do scap here 251// do scap here
250 QString cmd; 252 QString cmd;
251 cmd="cat /dev/fd0 > /tmp/cap"; 253 cmd="cat /dev/fd0 > /tmp/cap";
252 system(cmd.latin1()); 254 system(cmd.latin1());
253// qDebug("echo \"POST /scap/capture.cgi http1.1\" 255// qDebug("echo \"POST /scap/capture.cgi http1.1\"
254// echo \"Content-length: 153600\" 256// echo \"Content-length: 153600\"
255// echo \"Content-Type: image/gif\" 257// echo \"Content-Type: image/gif\"
256// echo \"HOST: www.handhelds.org\" 258// echo \"HOST: www.handhelds.org\"
257// echo \"\" 259// echo \"\"
258// cat /tmp/cap | nc h1.handhelds.org 80"); 260// cat /tmp/cap | nc h1.handhelds.org 80");
259 cmd="nc h1.handhelds.org 1011 </tmp/cap"; 261 cmd="nc h1.handhelds.org 1011 </tmp/cap";
260 qDebug("running command "+cmd); 262 qDebug("running command "+cmd);
261 263
262 system(cmd.latin1()); 264 system(cmd.latin1());
263 show(); 265 show();
264 } 266 }
265 267
266} 268}
267 269
268void ScreenshotControl::setTime(int newTime) { 270void ScreenshotControl::setTime(int newTime) {
269 delaySpin->setValue(newTime); 271 delaySpin->setValue(newTime);
270} 272}
271 273
272void ScreenshotControl::nameScreenshot(bool b) { 274void ScreenshotControl::nameScreenshot(bool b) {
273 275
274 276
275} 277}
276 278
277//=========================================================================== 279//===========================================================================
278 280
279ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) 281ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name )
280 : QWidget( parent, name ) { 282 : QWidget( parent, name ) {
281// qDebug("beginning applet"); 283// qDebug("beginning applet");
282 setFixedHeight( 18 ); 284 setFixedHeight( 18 );
283 setFixedWidth( 14 ); 285 setFixedWidth( 14 );
284 vc = new ScreenshotControl(this,"ScreenshotApplet");; 286 vc = new ScreenshotControl(this,"ScreenshotApplet");;
285// qDebug("new screenshotapplet"); 287// qDebug("new screenshotapplet");
286} 288}
287 289
288ScreenshotApplet::~ScreenshotApplet() { 290ScreenshotApplet::~ScreenshotApplet() {
289} 291}
290 292
291void ScreenshotApplet::mousePressEvent( QMouseEvent *) { 293void ScreenshotApplet::mousePressEvent( QMouseEvent *) {
292// if(!vc) 294// if(!vc)
293 vc = new ScreenshotControl; 295 vc = new ScreenshotControl;
294 QPoint curPos = mapToGlobal( rect().topLeft() ); 296 QPoint curPos = mapToGlobal( rect().topLeft() );
295 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); 297 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 );
296 vc->show(); 298 vc->show();
297 299
298} 300}
299 301
300void ScreenshotApplet::paintEvent( QPaintEvent* ) { 302void ScreenshotApplet::paintEvent( QPaintEvent* ) {
301 QPainter p(this); 303 QPainter p(this);
302 qDebug("paint pixmap"); 304 qDebug("paint pixmap");
303 p.drawPixmap( 0, 1, ( const char** ) snapshot_xpm ); 305 p.drawPixmap( 0, 1, ( const char** ) snapshot_xpm );
304 306
305} 307}
306 308