summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-02-09 04:13:08 (UTC)
committer llornkcor <llornkcor>2002-02-09 04:13:08 (UTC)
commit864a3a1dc5bdcae601626aa1f6b3cf8e85385cf3 (patch) (unidiff)
tree6f6f181c0730982e58166309323dfcbb718e6e1f
parentb440f07b1f20877618e33248a65bf069150d72c4 (diff)
downloadopie-864a3a1dc5bdcae601626aa1f6b3cf8e85385cf3.zip
opie-864a3a1dc5bdcae601626aa1f6b3cf8e85385cf3.tar.gz
opie-864a3a1dc5bdcae601626aa1f6b3cf8e85385cf3.tar.bz2
uses $HOME
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/screenshotapplet/screenshot.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/core/applets/screenshotapplet/screenshot.cpp b/core/applets/screenshotapplet/screenshot.cpp
index d70b57c..20e8554 100644
--- a/core/applets/screenshotapplet/screenshot.cpp
+++ b/core/applets/screenshotapplet/screenshot.cpp
@@ -1,189 +1,197 @@
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 <qapplication.h> 16#include <qapplication.h>
17#include <stdlib.h>
18
17 19
18#include <qpe/resource.h> 20#include <qpe/resource.h>
19#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
20#include <qpe/timestring.h> 22#include <qpe/timestring.h>
21#include <qpe/resource.h> 23#include <qpe/resource.h>
22#include <qpe/config.h> 24#include <qpe/config.h>
23#include <qpe/applnk.h> 25#include <qpe/applnk.h>
24#include <qpe/config.h> 26#include <qpe/config.h>
25 27
26 28#include <qdir.h>
27#include <qfileinfo.h> 29#include <qfileinfo.h>
28#include <qpoint.h> 30#include <qpoint.h>
29#include <qpushbutton.h> 31#include <qpushbutton.h>
30#include <qpainter.h> 32#include <qpainter.h>
31#include <qcombobox.h> 33#include <qcombobox.h>
32#include <qspinbox.h> 34#include <qspinbox.h>
33#include <qslider.h> 35#include <qslider.h>
34#include <qlayout.h> 36#include <qlayout.h>
35#include <qframe.h> 37#include <qframe.h>
36#include <qpixmap.h> 38#include <qpixmap.h>
37#include <qstring.h> 39#include <qstring.h>
38#include <qfile.h> 40#include <qfile.h>
39#include <qtimer.h> 41#include <qtimer.h>
40 42
41static char * snapshot_xpm[] = { 43static char * snapshot_xpm[] = {
42"16 16 10 1", 44"16 16 10 1",
43" c None", 45" c None",
44". c #000000", 46". c #000000",
45"+ c #00C000", 47"+ c #00C000",
46"@ c #585858", 48"@ c #585858",
47"# c #808080", 49"# c #808080",
48"$ c #00FF00", 50"$ c #00FF00",
49"% c #008000", 51"% c #008000",
50"& c #00FFFF", 52"& c #00FFFF",
51"* c #FF0000", 53"* c #FF0000",
52"= c #FFC0C0", 54"= c #FFC0C0",
53" ", 55" ",
54" ... ", 56" ... ",
55" ..+++..@#. ", 57" ..+++..@#. ",
56" .$++++++.#. ", 58" .$++++++.#. ",
57" .%$$++++++. ", 59" .%$$++++++. ",
58" .&%%$$++@***. ", 60" .&%%$$++@***. ",
59" .$&$++$=**@+. ", 61" .$&$++$=**@+. ",
60" .+$$+++@*$%%. ", 62" .+$$+++@*$%%. ",
61" .+++++%+++%%. ", 63" .+++++%+++%%. ",
62" .%%++++..+%%. ", 64" .%%++++..+%%. ",
63" ..%%+++++%%. ", 65" ..%%+++++%%. ",
64" ..%%+++%%. ", 66" ..%%+++%%. ",
65" ..%%+%%. ", 67" ..%%+%%. ",
66" ..%%.. ", 68" ..%%.. ",
67" .. ", 69" .. ",
68" "}; 70" "};
69 71
70 72
71ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name ) 73ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name )
72 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 74 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
73{ 75{
74 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 76 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
75// qDebug("screenshot control"); 77// qDebug("screenshot control");
76 QVBoxLayout *vbox = new QVBoxLayout( this ); 78 QVBoxLayout *vbox = new QVBoxLayout( this );
77// qDebug("new layout"); 79// qDebug("new layout");
78 delaySpin = new QSpinBox( 0,60,1, this, "Spinner" ); 80 delaySpin = new QSpinBox( 0,60,1, this, "Spinner" );
79// qDebug("new spinbox"); 81// qDebug("new spinbox");
80 delaySpin->setFocusPolicy( QWidget::NoFocus ); 82 delaySpin->setFocusPolicy( QWidget::NoFocus );
81 grabItButton= new QPushButton( this, "GrabButton" ); 83 grabItButton= new QPushButton( this, "GrabButton" );
82// qDebug("new pushbutton"); 84// qDebug("new pushbutton");
83 grabItButton ->setFocusPolicy( QWidget::TabFocus ); 85 grabItButton ->setFocusPolicy( QWidget::TabFocus );
84 grabItButton->setText("Snaphot"); 86 grabItButton->setText("Snaphot");
85 vbox->setMargin( 6 ); 87 vbox->setMargin( 6 );
86 vbox->setSpacing( 3 ); 88 vbox->setSpacing( 3 );
87 vbox->addWidget( delaySpin); 89 vbox->addWidget( delaySpin);
88 vbox->setMargin( 6 ); 90 vbox->setMargin( 6 );
89 vbox->setSpacing( 3 ); 91 vbox->setSpacing( 3 );
90 vbox->addWidget( grabItButton); 92 vbox->addWidget( grabItButton);
91 93
92 setFixedHeight( 100 ); 94 setFixedHeight( 100 );
93 setFixedWidth( sizeHint().width() ); 95 setFixedWidth( sizeHint().width() );
94 setFocusPolicy(QWidget::NoFocus); 96 setFocusPolicy(QWidget::NoFocus);
95 97
96 grabTimer= new QTimer(this,"grab timer"); 98 grabTimer= new QTimer(this,"grab timer");
97// qDebug("newTimer"); 99// qDebug("newTimer");
98 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) ); 100 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) );
99 101
100// Config cfg("Snapshot"); 102// Config cfg("Snapshot");
101// cfg.setGroup("General"); 103// cfg.setGroup("General");
102// delaySpin->setValue(cfg.readNumEntry("delay",0)); 104// delaySpin->setValue(cfg.readNumEntry("delay",0));
103 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) ); 105 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) );
104 106
105} 107}
106 108
107void ScreenshotControl::slotGrab() 109void ScreenshotControl::slotGrab()
108{ 110{
109// qDebug("SlotGrab"); 111// qDebug("SlotGrab");
110 hide(); 112 hide();
111 if ( delaySpin->value() ) { 113 if ( delaySpin->value() ) {
112 grabTimer->start( delaySpin->value() * 1000, true ); 114 grabTimer->start( delaySpin->value() * 1000, true );
113 } else { 115 } else {
114 show(); 116 show();
115 } 117 }
116} 118}
117 119
118 120
119void ScreenshotControl::grabTimerDone() 121void ScreenshotControl::grabTimerDone()
120{ 122{
121 performGrab(); 123 performGrab();
122} 124}
123 125
124void ScreenshotControl::savePixmap() 126void ScreenshotControl::savePixmap()
125{ 127{
126 DocLnk lnk; 128 DocLnk lnk;
127 QString fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true); 129 QString fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true);
128 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),""); 130 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),"");
129 131
130 fileName="/home/root/Documents/image/png/"+fileName+".png"; 132 QString dirName = QDir::homeDirPath()+"/Documents/image/png/";
133 if( !QDir( dirName).exists() ) {
134 qDebug("making dir "+dirName);
135 QString msg = "mkdir -p "+dirName;
136 system(msg.latin1());
137 }
138 fileName=dirName+fileName+".png";
131 lnk.setFile(fileName); //sets File property 139 lnk.setFile(fileName); //sets File property
132 snapshot.save( fileName,"PNG"); 140 snapshot.save( fileName,"PNG");
133 qDebug("saving file "+fileName); 141 qDebug("saving file "+fileName);
134 QFileInfo fi( fileName); 142 QFileInfo fi( fileName);
135 lnk.setName( fi.fileName()); //sets file name 143 lnk.setName( fi.fileName()); //sets file name
136 if(!lnk.writeLink()) 144 if(!lnk.writeLink())
137 qDebug("Writing doclink did not work"); 145 qDebug("Writing doclink did not work");
138 146
139 QPEApplication::beep(); 147 QPEApplication::beep();
140 148
141} 149}
142 150
143void ScreenshotControl::performGrab() 151void ScreenshotControl::performGrab()
144{ 152{
145 qDebug("grabbing screen"); 153 qDebug("grabbing screen");
146 grabTimer->stop(); 154 grabTimer->stop();
147 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() ); 155 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() );
148 show(); 156 show();
149 savePixmap(); 157 savePixmap();
150} 158}
151 159
152void ScreenshotControl::setTime(int newTime) 160void ScreenshotControl::setTime(int newTime)
153{ 161{
154 delaySpin->setValue(newTime); 162 delaySpin->setValue(newTime);
155} 163}
156 164
157//=========================================================================== 165//===========================================================================
158 166
159ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) 167ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name )
160 : QWidget( parent, name ) 168 : QWidget( parent, name )
161{ 169{
162// qDebug("beginning applet"); 170// qDebug("beginning applet");
163 setFixedHeight( 18 ); 171 setFixedHeight( 18 );
164 setFixedWidth( 14 ); 172 setFixedWidth( 14 );
165 vc = new ScreenshotControl; 173 vc = new ScreenshotControl;
166// qDebug("new screenshotapplet"); 174// qDebug("new screenshotapplet");
167} 175}
168 176
169ScreenshotApplet::~ScreenshotApplet() 177ScreenshotApplet::~ScreenshotApplet()
170{ 178{
171} 179}
172 180
173void ScreenshotApplet::mousePressEvent( QMouseEvent *) 181void ScreenshotApplet::mousePressEvent( QMouseEvent *)
174{ 182{
175// if(!vc) 183// if(!vc)
176 vc = new ScreenshotControl; 184 vc = new ScreenshotControl;
177 QPoint curPos = mapToGlobal( rect().topLeft() ); 185 QPoint curPos = mapToGlobal( rect().topLeft() );
178 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); 186 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 );
179 vc->show(); 187 vc->show();
180 188
181} 189}
182 190
183void ScreenshotApplet::paintEvent( QPaintEvent* ) 191void ScreenshotApplet::paintEvent( QPaintEvent* )
184{ 192{
185 QPainter p(this); 193 QPainter p(this);
186 qDebug("paint pixmap"); 194 qDebug("paint pixmap");
187 p.drawPixmap( 0, 1, ( const char** ) snapshot_xpm ); 195 p.drawPixmap( 0, 1, ( const char** ) snapshot_xpm );
188 196
189} 197}