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