summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-07-28 04:02:22 (UTC)
committer llornkcor <llornkcor>2004-07-28 04:02:22 (UTC)
commite98e9106df225b9e19a45a6f0e44193b1d018461 (patch) (unidiff)
tree2f2238d1f9549dd4fb645551abf88480a11d2dc3
parent347acd6001e00d0e57c4917f9a741ab887caf4cd (diff)
downloadopie-e98e9106df225b9e19a45a6f0e44193b1d018461.zip
opie-e98e9106df225b9e19a45a6f0e44193b1d018461.tar.gz
opie-e98e9106df225b9e19a45a6f0e44193b1d018461.tar.bz2
use copyfile method that doesnt squish filenames into latin1, so copying files with extended characters doesn't fail after ir receive
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/receiver.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp
index 8885256..d4ae323 100644
--- a/core/obex/receiver.cpp
+++ b/core/obex/receiver.cpp
@@ -1,202 +1,208 @@
1#include "obex.h" 1#include "obex.h"
2#include "receiver.h" 2#include "receiver.h"
3using namespace OpieObex; 3using namespace OpieObex;
4 4
5/* OPIE */ 5/* OPIE */
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7#include <qpe/applnk.h> 7#include <qpe/applnk.h>
8#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
9#include <qpe/qcopenvelope_qws.h> 9#include <qpe/qcopenvelope_qws.h>
10#include <qpe/filemanager.h>
10using namespace Opie::Core; 11using namespace Opie::Core;
11 12
12/* QT */ 13/* QT */
13#include <qfileinfo.h> 14#include <qfileinfo.h>
14#include <qlabel.h> 15#include <qlabel.h>
15#include <qtextview.h> 16#include <qtextview.h>
16#include <qpushbutton.h> 17#include <qpushbutton.h>
17 18
18/* STD */ 19/* STD */
19#include <sys/types.h> 20#include <sys/types.h>
20#include <sys/stat.h> 21#include <sys/stat.h>
21#include <sys/mman.h> 22#include <sys/mman.h>
22#include <stdlib.h> // int system 23#include <stdlib.h> // int system
23#include <unistd.h> 24#include <unistd.h>
24#include <fcntl.h> 25#include <fcntl.h>
25 26
26/* TRANSLATOR OpieObex::Receiver */ 27/* TRANSLATOR OpieObex::Receiver */
27 28
28Receiver::Receiver() { 29Receiver::Receiver() {
29 m_obex = new Obex(this, "Receiver"); 30 m_obex = new Obex(this, "Receiver");
30 connect(m_obex, SIGNAL(receivedFile(const QString&) ), 31 connect(m_obex, SIGNAL(receivedFile(const QString&) ),
31 this, SLOT(slotReceived(const QString&) ) ); 32 this, SLOT(slotReceived(const QString&) ) );
32 m_obex->receive(); 33 m_obex->receive();
33} 34}
34Receiver::~Receiver() { 35Receiver::~Receiver() {
35 m_obex->setReceiveEnabled( false ); 36 m_obex->setReceiveEnabled( false );
36 delete m_obex; 37 delete m_obex;
37} 38}
38void Receiver::slotReceived( const QString& _file ) { 39void Receiver::slotReceived( const QString& _file ) {
39 QString file = _file; 40 QString file = _file;
40 int check = checkFile(file); 41 int check = checkFile(file);
41 if ( check == AddressBook ) 42 if ( check == AddressBook )
42 handleAddr( file ); 43 handleAddr( file );
43 else if ( check == Datebook ) 44 else if ( check == Datebook )
44 handleDateTodo( file ); 45 handleDateTodo( file );
45 else 46 else
46 handleOther( file ); 47 handleOther( file );
47} 48}
48void Receiver::handleAddr( const QString& str ) { 49void Receiver::handleAddr( const QString& str ) {
49 QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); 50 QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" );
50 e << str; 51 e << str;
51} 52}
52/* we can not say for sure if it's a VEevent ot VTodo */ 53/* we can not say for sure if it's a VEevent ot VTodo */
53void Receiver::handleDateTodo( const QString& str ) { 54void Receiver::handleDateTodo( const QString& str ) {
54 QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); 55 QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)");
55 e0 << str; 56 e0 << str;
56 QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); 57 QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" );
57 e1 << str; 58 e1 << str;
58} 59}
59/* 60/*
60 * Handle other asks if it should accept the 61 * Handle other asks if it should accept the
61 * beamed object and creates a DocLnk 62 * beamed object and creates a DocLnk
62 */ 63 */
63void Receiver::handleOther( const QString& other ) { 64void Receiver::handleOther( const QString& other ) {
64 OtherHandler* hand = new OtherHandler(); 65 OtherHandler* hand = new OtherHandler();
65 hand->handle( other ); 66 hand->handle( other );
66} 67}
67void Receiver::tidyUp( QString& _file, const QString& ending) { 68void Receiver::tidyUp( QString& _file, const QString& ending) {
68 /* libversit fails on BASE64 encoding we try to sed it away */ 69 /* libversit fails on BASE64 encoding we try to sed it away */
69 QString file = _file; 70 QString file = _file;
70 char foo[24]; // big enough 71 char foo[24]; // big enough
71 (void)::strcpy(foo, "/tmp/opie-XXXXXX"); 72 (void)::strcpy(foo, "/tmp/opie-XXXXXX");
72 73
73 int fd = ::mkstemp(foo); 74 int fd = ::mkstemp(foo);
74 75
75 if ( fd == -1 ) 76 if ( fd == -1 )
76 return; 77 return;
77 78
78 (void)::strncat( foo, ending.latin1(), 4 ); 79 (void)::strncat( foo, ending.latin1(), 4 );
79 _file = QString::fromLatin1( foo ); 80 _file = QString::fromLatin1( foo );
80 QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) ); 81 QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) );
81 owarn << "Executing: " << cmd << "" << oendl; 82 owarn << "Executing: " << cmd << "" << oendl;
82 (void)::system( cmd.latin1() ); 83 (void)::system( cmd.latin1() );
83 84
84 cmd = QString("rm %1").arg( Global::shellQuote(file) ); 85 cmd = QString("rm %1").arg( Global::shellQuote(file) );
85 (void)::system( cmd.latin1() ); 86 (void)::system( cmd.latin1() );
86} 87}
87int Receiver::checkFile( QString& file ) { 88int Receiver::checkFile( QString& file ) {
88 owarn << "check file!! " << file << "" << oendl; 89 owarn << "check file!! " << file << "" << oendl;
89 int ret; 90 int ret;
90 QString ending; 91 QString ending;
91 92
92 if (file.right(4) == ".vcs" ) { 93 if (file.right(4) == ".vcs" ) {
93 ret = Datebook; 94 ret = Datebook;
94 ending = QString::fromLatin1(".vcs"); 95 ending = QString::fromLatin1(".vcs");
95 }else if ( file.right(4) == ".vcf") { 96 }else if ( file.right(4) == ".vcf") {
96 ret = AddressBook; 97 ret = AddressBook;
97 ending = QString::fromLatin1(".vcf"); 98 ending = QString::fromLatin1(".vcf");
98 }else 99 }else
99 ret = Other; 100 ret = Other;
100 101
101 102
102 if (ending.isEmpty() ) 103 if (ending.isEmpty() )
103 return ret; 104 return ret;
104 105
105 /** 106 /**
106 * currently the parser is broken in regard of BASE64 encoding 107 * currently the parser is broken in regard of BASE64 encoding
107 * and M$ likes to send that. So we will executed a small 108 * and M$ likes to send that. So we will executed a small
108 * tidy up system sed script 109 * tidy up system sed script
109 * At this point we can also remove umlaute from the filename 110 * At this point we can also remove umlaute from the filename
110 */ 111 */
111 tidyUp( file, ending ); 112 tidyUp( file, ending );
112 113
113 owarn << "check it now " << ret << "" << oendl; 114 owarn << "check it now " << ret << "" << oendl;
114 return ret; 115 return ret;
115} 116}
116 117
117/* TRANSLATOR OpieObex::OtherHandler */ 118/* TRANSLATOR OpieObex::OtherHandler */
118 119
119OtherHandler::OtherHandler() 120OtherHandler::OtherHandler()
120 : QVBox() 121 : QVBox()
121{ 122{
122 QHBox* box = new QHBox(this); 123 QHBox* box = new QHBox(this);
123 QLabel* lbl = new QLabel(box); 124 QLabel* lbl = new QLabel(box);
124 lbl->setText(tr("<qt><b>Received:</b></qt>")); 125 lbl->setText(tr("<qt><b>Received:</b></qt>"));
125 m_na = new QLabel(box); 126 m_na = new QLabel(box);
126 127
127 QFrame* frame = new QFrame(this); 128 QFrame* frame = new QFrame(this);
128 frame->setFrameShape( QFrame::HLine ); 129 frame->setFrameShape( QFrame::HLine );
129 frame->setFrameShadow( QFrame::Sunken ); 130 frame->setFrameShadow( QFrame::Sunken );
130 131
131 m_view = new QTextView(this); 132 m_view = new QTextView(this);
132 133
133 box = new QHBox(this); 134 box = new QHBox(this);
134 QPushButton *but = new QPushButton(box); 135 QPushButton *but = new QPushButton(box);
135 but->setText(tr("Accept") ); 136 but->setText(tr("Accept") );
136 connect(but, SIGNAL(clicked() ), 137 connect(but, SIGNAL(clicked() ),
137 this, SLOT(accept()) ); 138 this, SLOT(accept()) );
138 139
139 but = new QPushButton(box); 140 but = new QPushButton(box);
140 but->setText(tr("Deny") ); 141 but->setText(tr("Deny") );
141 connect(but, SIGNAL(clicked() ), 142 connect(but, SIGNAL(clicked() ),
142 this, SLOT(deny() ) ); 143 this, SLOT(deny() ) );
143 144
144 raise(); 145 raise();
145 showMaximized(); 146 showMaximized();
146} 147}
147OtherHandler::~OtherHandler() { 148OtherHandler::~OtherHandler() {
148 149
149} 150}
150void OtherHandler::handle( const QString& file ) { 151void OtherHandler::handle( const QString& file ) {
151 m_file = file; 152 m_file = file;
152 m_na->setText(file); 153 m_na->setText(file);
153 DocLnk lnk(file); 154 DocLnk lnk(file);
154 owarn << " " << lnk.type() << " " << lnk.icon() << "" << oendl; 155 owarn << " " << lnk.type() << " " << lnk.icon() << "" << oendl;
155 156
156 QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() ); 157 QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() );
157 m_view->setText( str ); 158 m_view->setText( str );
158} 159}
159 160
160/* 161/*
161 * hehe evil evil mmap ahead :) 162 * hehe evil evil mmap ahead :)
162 * we quickly copy the file and then we'll create a DocLnk for it 163 * we quickly copy the file and then we'll create a DocLnk for it
163 */ 164 */
164void OtherHandler::accept() { 165void OtherHandler::accept() {
165 QString na = targetName( m_file ); 166 QString na = targetName( m_file );
166 copy(m_file, na ); 167 copy(m_file, na );
167 DocLnk lnk(na); 168 DocLnk lnk(na);
168 lnk.writeLink(); 169 lnk.writeLink();
169 QFile::remove(m_file); 170 QFile::remove(m_file);
170 delete this; 171 delete this;
171} 172}
172void OtherHandler::deny() { 173void OtherHandler::deny() {
173 QFile::remove( m_file ); 174 QFile::remove( m_file );
174 delete this; 175 delete this;
175} 176}
176QString OtherHandler::targetName( const QString& file ) { 177QString OtherHandler::targetName( const QString& file ) {
177 QFileInfo info( file ); 178 QFileInfo info( file );
178 179
179 /* $HOME needs to be set!!!! */ 180 /* $HOME needs to be set!!!! */
180 Global::createDocDir(); 181 Global::createDocDir();
181 182
182 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); 183 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName();
183 QString newFileBase = newFile; 184 QString newFileBase = newFile;
184 185
185 int trie = 0; 186 int trie = 0;
186 while (QFile::exists(newFile + "."+info.extension() ) ) { 187 while (QFile::exists(newFile + "."+info.extension() ) ) {
187 newFile = newFileBase + "_"+QString::number(trie) ; 188 newFile = newFileBase + "_"+QString::number(trie) ;
188 trie++; 189 trie++;
189 } 190 }
190 newFile += "." + info.extension(); 191 newFile += "." + info.extension();
191 192
192 return newFile; 193 return newFile;
193} 194}
194 195
195/* fast cpy */ 196/* fast cpy */
196void OtherHandler::copy(const QString& src, const QString& file) { 197void OtherHandler::copy(const QString& src, const QString& file) {
197 owarn << "src " << src << ", dest " << file << "" << oendl; 198 owarn << "src " << src << ", dest " << file << "" << oendl;
198 QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )). 199 FileManager *fm;
199 arg( Global::shellQuote( file ) ); 200 if(!fm->copyFile(src,file)) {
200 ::system( cmd.latin1() ); 201 owarn << "Copy failed" << oendl;
202 }
203
204// QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )).
205// arg( Global::shellQuote( file ) );
206// ::system( cmd.latin1() );
201 // done 207 // done
202} 208}