author | kergoth <kergoth> | 2003-08-09 17:29:36 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-08-09 17:29:36 (UTC) |
commit | a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93 (patch) (unidiff) | |
tree | 5ce78e1a5dedd31b7851d53bf9f072bd44edd1b0 /core/obex/receiver.cpp | |
parent | a7e015198a8c5ad3b6e144a9032b059086253e00 (diff) | |
download | opie-a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93.zip opie-a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93.tar.gz opie-a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93.tar.bz2 |
Merge from BRANCH_1_0
-rw-r--r-- | core/obex/receiver.cpp | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp index 31c6afe..bf9e30c 100644 --- a/core/obex/receiver.cpp +++ b/core/obex/receiver.cpp | |||
@@ -1,100 +1,143 @@ | |||
1 | #include <sys/types.h> | 1 | #include <sys/types.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/mman.h> | 3 | #include <sys/mman.h> |
4 | #include <stdlib.h> // int system | ||
4 | #include <unistd.h> | 5 | #include <unistd.h> |
5 | 6 | ||
6 | #include <fcntl.h> | 7 | #include <fcntl.h> |
7 | 8 | ||
8 | #include <qfile.h> | 9 | #include <qfile.h> |
9 | #include <qfileinfo.h> | 10 | #include <qfileinfo.h> |
10 | #include <qlabel.h> | 11 | #include <qlabel.h> |
11 | #include <qhbox.h> | 12 | #include <qhbox.h> |
13 | #include <qregexp.h> | ||
12 | #include <qtextview.h> | 14 | #include <qtextview.h> |
13 | #include <qpushbutton.h> | 15 | #include <qpushbutton.h> |
14 | 16 | ||
15 | #include <qpe/applnk.h> | 17 | #include <qpe/applnk.h> |
16 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
20 | #include <qpe/global.h> | ||
18 | 21 | ||
19 | #include "obex.h" | 22 | #include "obex.h" |
20 | #include "receiver.h" | 23 | #include "receiver.h" |
21 | 24 | ||
22 | using namespace OpieObex; | 25 | using namespace OpieObex; |
23 | 26 | ||
27 | /* TRANSLATOR OpieObex::Receiver */ | ||
28 | |||
24 | Receiver::Receiver() { | 29 | Receiver::Receiver() { |
25 | m_obex = new Obex(this, "Receiver"); | 30 | m_obex = new Obex(this, "Receiver"); |
26 | connect(m_obex, SIGNAL(receivedFile(const QString& ) ), | 31 | connect(m_obex, SIGNAL(receivedFile(const QString& ) ), |
27 | this, SLOT(slotReceived(const QString& ) ) ); | 32 | this, SLOT(slotReceived(const QString& ) ) ); |
28 | m_obex->receive(); | 33 | m_obex->receive(); |
29 | } | 34 | } |
30 | Receiver::~Receiver() { | 35 | Receiver::~Receiver() { |
31 | m_obex->setReceiveEnabled( false ); | 36 | m_obex->setReceiveEnabled( false ); |
32 | delete m_obex; | 37 | delete m_obex; |
33 | } | 38 | } |
34 | void Receiver::slotReceived( const QString& file ) { | 39 | void Receiver::slotReceived( const QString& _file ) { |
40 | QString file = _file; | ||
35 | int check = checkFile(file); | 41 | int check = checkFile(file); |
36 | if ( check == AddressBook ) | 42 | if ( check == AddressBook ) |
37 | handleAddr( file ); | 43 | handleAddr( file ); |
38 | else if ( check == Datebook ) | 44 | else if ( check == Datebook ) |
39 | handleDateTodo( file ); | 45 | handleDateTodo( file ); |
40 | else | 46 | else |
41 | handleOther( file ); | 47 | handleOther( file ); |
42 | } | 48 | } |
43 | void Receiver::handleAddr( const QString& str ) { | 49 | void Receiver::handleAddr( const QString& str ) { |
44 | QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); | 50 | QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); |
45 | e << str; | 51 | e << str; |
46 | } | 52 | } |
47 | /* 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 */ |
48 | void Receiver::handleDateTodo( const QString& str ) { | 54 | void Receiver::handleDateTodo( const QString& str ) { |
49 | QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); | 55 | QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); |
50 | e0 << str; | 56 | e0 << str; |
51 | QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); | 57 | QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); |
52 | e1 << str; | 58 | e1 << str; |
53 | } | 59 | } |
54 | /* | 60 | /* |
55 | * Handle other asks if it should accept the | 61 | * Handle other asks if it should accept the |
56 | * beamed object and creates a DocLnk | 62 | * beamed object and creates a DocLnk |
57 | */ | 63 | */ |
58 | void Receiver::handleOther( const QString& other ) { | 64 | void Receiver::handleOther( const QString& other ) { |
59 | OtherHandler* hand = new OtherHandler(); | 65 | OtherHandler* hand = new OtherHandler(); |
60 | hand->handle( other ); | 66 | hand->handle( other ); |
61 | } | 67 | } |
62 | int Receiver::checkFile( const QString& file ) { | 68 | void Receiver::tidyUp( QString& _file, const QString& ending) { |
69 | /* libversit fails on BASE64 encoding we try to sed it away */ | ||
70 | QString file = _file; | ||
71 | char foo[24]; // big enough | ||
72 | (void)::strcpy(foo, "/tmp/opie-XXXXXX"); | ||
73 | |||
74 | int fd = ::mkstemp(foo); | ||
75 | |||
76 | if ( fd == -1 ) | ||
77 | return; | ||
78 | |||
79 | (void)::strncat( foo, ending.latin1(), 4 ); | ||
80 | _file = QString::fromLatin1( foo ); | ||
81 | QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) ); | ||
82 | qWarning("Executing: %s", cmd.latin1() ); | ||
83 | (void)::system( cmd.latin1() ); | ||
84 | |||
85 | cmd = QString("rm %1").arg( Global::shellQuote(file) ); | ||
86 | (void)::system( cmd.latin1() ); | ||
87 | } | ||
88 | int Receiver::checkFile( QString& file ) { | ||
63 | qWarning("check file!! %s", file.latin1() ); | 89 | qWarning("check file!! %s", file.latin1() ); |
64 | int ret; | 90 | int ret; |
91 | QString ending; | ||
92 | |||
65 | if (file.right(4) == ".vcs" ) { | 93 | if (file.right(4) == ".vcs" ) { |
66 | ret = Datebook; | 94 | ret = Datebook; |
95 | ending = QString::fromLatin1(".vcs"); | ||
67 | }else if ( file.right(4) == ".vcf") { | 96 | }else if ( file.right(4) == ".vcf") { |
68 | ret = AddressBook; | 97 | ret = AddressBook; |
98 | ending = QString::fromLatin1(".vcf"); | ||
69 | }else | 99 | }else |
70 | ret = Other; | 100 | ret = Other; |
71 | 101 | ||
72 | 102 | ||
103 | if (ending.isEmpty() ) | ||
104 | return ret; | ||
105 | |||
106 | /** | ||
107 | * currently the parser is broken in regard of BASE64 encoding | ||
108 | * and M$ likes to send that. So we will executed a small | ||
109 | * tidy up system sed script | ||
110 | * At this point we can also remove umlaute from the filename | ||
111 | */ | ||
112 | tidyUp( file, ending ); | ||
113 | |||
73 | qWarning("check it now %d", ret ); | 114 | qWarning("check it now %d", ret ); |
74 | return ret; | 115 | return ret; |
75 | } | 116 | } |
76 | 117 | ||
118 | /* TRANSLATOR OpieObex::OtherHandler */ | ||
119 | |||
77 | OtherHandler::OtherHandler() | 120 | OtherHandler::OtherHandler() |
78 | : QVBox() | 121 | : QVBox() |
79 | { | 122 | { |
80 | QHBox* box = new QHBox(this); | 123 | QHBox* box = new QHBox(this); |
81 | QLabel* lbl = new QLabel(box); | 124 | QLabel* lbl = new QLabel(box); |
82 | lbl->setText(tr("<qt><b>Received:</b></qt>")); | 125 | lbl->setText(tr("<qt><b>Received:</b></qt>")); |
83 | m_na = new QLabel(box); | 126 | m_na = new QLabel(box); |
84 | 127 | ||
85 | QFrame* frame = new QFrame(this); | 128 | QFrame* frame = new QFrame(this); |
86 | frame->setFrameShape( QFrame::HLine ); | 129 | frame->setFrameShape( QFrame::HLine ); |
87 | frame->setFrameShadow( QFrame::Sunken ); | 130 | frame->setFrameShadow( QFrame::Sunken ); |
88 | 131 | ||
89 | m_view = new QTextView(this); | 132 | m_view = new QTextView(this); |
90 | 133 | ||
91 | box = new QHBox(this); | 134 | box = new QHBox(this); |
92 | QPushButton *but = new QPushButton(box); | 135 | QPushButton *but = new QPushButton(box); |
93 | but->setText(tr("Accept") ); | 136 | but->setText(tr("Accept") ); |
94 | connect(but, SIGNAL(clicked() ), | 137 | connect(but, SIGNAL(clicked() ), |
95 | this, SLOT(accept()) ); | 138 | this, SLOT(accept()) ); |
96 | 139 | ||
97 | but = new QPushButton(box); | 140 | but = new QPushButton(box); |
98 | but->setText(tr("Deny") ); | 141 | but->setText(tr("Deny") ); |
99 | connect(but, SIGNAL(clicked() ), | 142 | connect(but, SIGNAL(clicked() ), |
100 | this, SLOT(deny() ) ); | 143 | this, SLOT(deny() ) ); |
@@ -112,61 +155,49 @@ void OtherHandler::handle( const QString& file ) { | |||
112 | qWarning(" %s %s", lnk.type().latin1(), lnk.icon().latin1() ); | 155 | qWarning(" %s %s", lnk.type().latin1(), lnk.icon().latin1() ); |
113 | 156 | ||
114 | 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() ); |
115 | m_view->setText( str ); | 158 | m_view->setText( str ); |
116 | } | 159 | } |
117 | 160 | ||
118 | /* | 161 | /* |
119 | * hehe evil evil mmap ahead :) | 162 | * hehe evil evil mmap ahead :) |
120 | * 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 |
121 | */ | 164 | */ |
122 | void OtherHandler::accept() { | 165 | void OtherHandler::accept() { |
123 | QString na = targetName( m_file ); | 166 | QString na = targetName( m_file ); |
124 | copy(m_file, na ); | 167 | copy(m_file, na ); |
125 | DocLnk lnk(na); | 168 | DocLnk lnk(na); |
126 | lnk.writeLink(); | 169 | lnk.writeLink(); |
127 | QFile::remove(m_file); | 170 | QFile::remove(m_file); |
128 | delete this; | 171 | delete this; |
129 | } | 172 | } |
130 | void OtherHandler::deny() { | 173 | void OtherHandler::deny() { |
131 | QFile::remove( m_file ); | 174 | QFile::remove( m_file ); |
132 | delete this; | 175 | delete this; |
133 | } | 176 | } |
134 | QString OtherHandler::targetName( const QString& file ) { | 177 | QString OtherHandler::targetName( const QString& file ) { |
135 | QFileInfo info( file ); | 178 | QFileInfo info( file ); |
179 | |||
180 | /* $HOME needs to be set!!!! */ | ||
181 | Global::createDocDir(); | ||
182 | |||
136 | QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); | 183 | QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); |
137 | QString newFileBase = newFile; | 184 | QString newFileBase = newFile; |
138 | 185 | ||
139 | int trie = 0; | 186 | int trie = 0; |
140 | while (QFile::exists(newFile + "."+info.extension() ) ) { | 187 | while (QFile::exists(newFile + "."+info.extension() ) ) { |
141 | newFile = newFileBase + "_"+QString::number(trie) ; | 188 | newFile = newFileBase + "_"+QString::number(trie) ; |
142 | trie++; | 189 | trie++; |
143 | } | 190 | } |
144 | newFile += "." + info.extension(); | 191 | newFile += "." + info.extension(); |
145 | 192 | ||
146 | return newFile; | 193 | return newFile; |
147 | } | 194 | } |
148 | 195 | ||
149 | /* fast cpy */ | 196 | /* fast cpy */ |
150 | void OtherHandler::copy(const QString& src, const QString& file) { | 197 | void OtherHandler::copy(const QString& src, const QString& file) { |
151 | qWarning("src %s, dest %s", src.latin1(),file.latin1() ); | 198 | qWarning("src %s, dest %s", src.latin1(),file.latin1() ); |
152 | int src_fd = ::open( QFile::encodeName( src ), O_RDONLY ); | 199 | QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )). |
153 | int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC, | 200 | arg( Global::shellQuote( file ) ); |
154 | S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP ); | 201 | ::system( cmd.latin1() ); |
155 | |||
156 | struct stat stater; | ||
157 | ::fstat(src_fd, &stater ); | ||
158 | ::lseek(to_fd, stater.st_size-1, SEEK_SET ); | ||
159 | ::write(to_fd, "", 1 ); | ||
160 | |||
161 | void *src_addr, *dest_addr; | ||
162 | src_addr = ::mmap(0, stater.st_size, PROT_READ, | ||
163 | MAP_FILE | MAP_SHARED, src_fd, 0 ); | ||
164 | dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE, | ||
165 | MAP_FILE | MAP_PRIVATE, to_fd, 0 ); | ||
166 | |||
167 | ::memcpy(dest_addr , src_addr, stater.st_size ); | ||
168 | ::munmap(src_addr , stater.st_size ); | ||
169 | ::munmap(dest_addr, stater.st_size ); | ||
170 | |||
171 | // done | 202 | // done |
172 | } | 203 | } |