summaryrefslogtreecommitdiff
authorzecke <zecke>2003-02-16 21:01:09 (UTC)
committer zecke <zecke>2003-02-16 21:01:09 (UTC)
commit892a453a931b41967c7dca72097da9c5be7f84d6 (patch) (unidiff)
treec687518f02064dd5d7c94f57e519243dd3ea5dfe
parent64178d4839f12540b8a3d19cf79c9c2b1d33707e (diff)
downloadopie-892a453a931b41967c7dca72097da9c5be7f84d6.zip
opie-892a453a931b41967c7dca72097da9c5be7f84d6.tar.gz
opie-892a453a931b41967c7dca72097da9c5be7f84d6.tar.bz2
its memcpy(destination, src
and not vice versa....
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/receiver.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp
index d5a7271..31c6afe 100644
--- a/core/obex/receiver.cpp
+++ b/core/obex/receiver.cpp
@@ -1,170 +1,172 @@
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 <unistd.h> 4#include <unistd.h>
5 5
6#include <fcntl.h> 6#include <fcntl.h>
7 7
8#include <qfile.h> 8#include <qfile.h>
9#include <qfileinfo.h> 9#include <qfileinfo.h>
10#include <qlabel.h> 10#include <qlabel.h>
11#include <qhbox.h> 11#include <qhbox.h>
12#include <qtextview.h> 12#include <qtextview.h>
13#include <qpushbutton.h> 13#include <qpushbutton.h>
14 14
15#include <qpe/applnk.h> 15#include <qpe/applnk.h>
16#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
17#include <qpe/qcopenvelope_qws.h> 17#include <qpe/qcopenvelope_qws.h>
18 18
19#include "obex.h" 19#include "obex.h"
20#include "receiver.h" 20#include "receiver.h"
21 21
22using namespace OpieObex; 22using namespace OpieObex;
23 23
24Receiver::Receiver() { 24Receiver::Receiver() {
25 m_obex = new Obex(this, "Receiver"); 25 m_obex = new Obex(this, "Receiver");
26 connect(m_obex, SIGNAL(receivedFile(const QString& ) ), 26 connect(m_obex, SIGNAL(receivedFile(const QString& ) ),
27 this, SLOT(slotReceived(const QString& ) ) ); 27 this, SLOT(slotReceived(const QString& ) ) );
28 m_obex->receive(); 28 m_obex->receive();
29} 29}
30Receiver::~Receiver() { 30Receiver::~Receiver() {
31 m_obex->setReceiveEnabled( false ); 31 m_obex->setReceiveEnabled( false );
32 delete m_obex; 32 delete m_obex;
33} 33}
34void Receiver::slotReceived( const QString& file ) { 34void Receiver::slotReceived( const QString& file ) {
35 int check = checkFile(file); 35 int check = checkFile(file);
36 if ( check == AddressBook ) 36 if ( check == AddressBook )
37 handleAddr( file ); 37 handleAddr( file );
38 else if ( check == Datebook ) 38 else if ( check == Datebook )
39 handleDateTodo( file ); 39 handleDateTodo( file );
40 else 40 else
41 handleOther( file ); 41 handleOther( file );
42} 42}
43void Receiver::handleAddr( const QString& str ) { 43void Receiver::handleAddr( const QString& str ) {
44 QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); 44 QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" );
45 e << str; 45 e << str;
46} 46}
47/* we can not say for sure if it's a VEevent ot VTodo */ 47/* we can not say for sure if it's a VEevent ot VTodo */
48void Receiver::handleDateTodo( const QString& str ) { 48void Receiver::handleDateTodo( const QString& str ) {
49 QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); 49 QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)");
50 e0 << str; 50 e0 << str;
51 QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); 51 QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" );
52 e1 << str; 52 e1 << str;
53} 53}
54/* 54/*
55 * Handle other asks if it should accept the 55 * Handle other asks if it should accept the
56 * beamed object and creates a DocLnk 56 * beamed object and creates a DocLnk
57 */ 57 */
58void Receiver::handleOther( const QString& other ) { 58void Receiver::handleOther( const QString& other ) {
59 OtherHandler* hand = new OtherHandler(); 59 OtherHandler* hand = new OtherHandler();
60 hand->handle( other ); 60 hand->handle( other );
61} 61}
62int Receiver::checkFile( const QString& file ) { 62int Receiver::checkFile( const QString& file ) {
63 qWarning("check file!! %s", file.latin1() ); 63 qWarning("check file!! %s", file.latin1() );
64 int ret; 64 int ret;
65 if (file.right(4) == ".vcs" ) { 65 if (file.right(4) == ".vcs" ) {
66 ret = Datebook; 66 ret = Datebook;
67 }else if ( file.right(4) == ".vcf") { 67 }else if ( file.right(4) == ".vcf") {
68 ret = AddressBook; 68 ret = AddressBook;
69 }else 69 }else
70 ret = Other; 70 ret = Other;
71 71
72 72
73 qWarning("check it now %d", ret ); 73 qWarning("check it now %d", ret );
74 return ret; 74 return ret;
75} 75}
76 76
77OtherHandler::OtherHandler() 77OtherHandler::OtherHandler()
78 : QVBox() 78 : QVBox()
79{ 79{
80 QHBox* box = new QHBox(this); 80 QHBox* box = new QHBox(this);
81 QLabel* lbl = new QLabel(box); 81 QLabel* lbl = new QLabel(box);
82 lbl->setText(tr("<qt><b>Received:</b></qt>")); 82 lbl->setText(tr("<qt><b>Received:</b></qt>"));
83 m_na = new QLabel(box); 83 m_na = new QLabel(box);
84 84
85 QFrame* frame = new QFrame(this); 85 QFrame* frame = new QFrame(this);
86 frame->setFrameShape( QFrame::HLine ); 86 frame->setFrameShape( QFrame::HLine );
87 frame->setFrameShadow( QFrame::Sunken ); 87 frame->setFrameShadow( QFrame::Sunken );
88 88
89 m_view = new QTextView(this); 89 m_view = new QTextView(this);
90 90
91 box = new QHBox(this); 91 box = new QHBox(this);
92 QPushButton *but = new QPushButton(box); 92 QPushButton *but = new QPushButton(box);
93 but->setText(tr("Accept") ); 93 but->setText(tr("Accept") );
94 connect(but, SIGNAL(clicked() ), 94 connect(but, SIGNAL(clicked() ),
95 this, SLOT(accept()) ); 95 this, SLOT(accept()) );
96 96
97 but = new QPushButton(box); 97 but = new QPushButton(box);
98 but->setText(tr("Deny") ); 98 but->setText(tr("Deny") );
99 connect(but, SIGNAL(clicked() ), 99 connect(but, SIGNAL(clicked() ),
100 this, SLOT(deny() ) ); 100 this, SLOT(deny() ) );
101 101
102 raise(); 102 raise();
103 showMaximized(); 103 showMaximized();
104} 104}
105OtherHandler::~OtherHandler() { 105OtherHandler::~OtherHandler() {
106 106
107} 107}
108void OtherHandler::handle( const QString& file ) { 108void OtherHandler::handle( const QString& file ) {
109 m_file = file; 109 m_file = file;
110 m_na->setText(file); 110 m_na->setText(file);
111 DocLnk lnk(file); 111 DocLnk lnk(file);
112 qWarning(" %s %s", lnk.type().latin1(), lnk.icon().latin1() ); 112 qWarning(" %s %s", lnk.type().latin1(), lnk.icon().latin1() );
113 113
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() ); 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() );
115 m_view->setText( str ); 115 m_view->setText( str );
116} 116}
117 117
118/* 118/*
119 * hehe evil evil mmap ahead :) 119 * hehe evil evil mmap ahead :)
120 * we quickly copy the file and then we'll create a DocLnk for it 120 * we quickly copy the file and then we'll create a DocLnk for it
121 */ 121 */
122void OtherHandler::accept() { 122void OtherHandler::accept() {
123 QString na = targetName( m_file ); 123 QString na = targetName( m_file );
124 copy(m_file, na ); 124 copy(m_file, na );
125 DocLnk lnk(na); 125 DocLnk lnk(na);
126 lnk.writeLink(); 126 lnk.writeLink();
127 QFile::remove(m_file); 127 QFile::remove(m_file);
128 delete this; 128 delete this;
129} 129}
130void OtherHandler::deny() { 130void OtherHandler::deny() {
131 QFile::remove( m_file ); 131 QFile::remove( m_file );
132 delete this; 132 delete this;
133} 133}
134QString OtherHandler::targetName( const QString& file ) { 134QString OtherHandler::targetName( const QString& file ) {
135 QFileInfo info( file ); 135 QFileInfo info( file );
136 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); 136 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName();
137 QString newFileBase = newFile; 137 QString newFileBase = newFile;
138 138
139 int trie = 0; 139 int trie = 0;
140 while (QFile::exists(newFile + info.extension() ) ) { 140 while (QFile::exists(newFile + "."+info.extension() ) ) {
141 newFile = newFileBase + "_"+QString::number(trie) ; 141 newFile = newFileBase + "_"+QString::number(trie) ;
142 trie++; 142 trie++;
143 } 143 }
144 newFile += info.extension(); 144 newFile += "." + info.extension();
145 145
146 return newFile; 146 return newFile;
147} 147}
148 148
149/* fast cpy */ 149/* fast cpy */
150void OtherHandler::copy(const QString& src, const QString& file) { 150void OtherHandler::copy(const QString& src, const QString& file) {
151 qWarning("src %s, dest %s", src.latin1(),file.latin1() );
151 int src_fd = ::open( QFile::encodeName( src ), O_RDONLY ); 152 int src_fd = ::open( QFile::encodeName( src ), O_RDONLY );
152 int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC, 153 int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC,
153 S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP ); 154 S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP );
154 155
155 struct stat stater; 156 struct stat stater;
156 ::fstat(src_fd, &stater ); 157 ::fstat(src_fd, &stater );
157 ::lseek(to_fd, stater.st_size-1, SEEK_SET ); 158 ::lseek(to_fd, stater.st_size-1, SEEK_SET );
159 ::write(to_fd, "", 1 );
158 160
159 void *src_addr, *dest_addr; 161 void *src_addr, *dest_addr;
160 src_addr = ::mmap(0, stater.st_size, PROT_READ, 162 src_addr = ::mmap(0, stater.st_size, PROT_READ,
161 MAP_FILE | MAP_SHARED, src_fd, 0 ); 163 MAP_FILE | MAP_SHARED, src_fd, 0 );
162 dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE, 164 dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE,
163 MAP_FILE | MAP_PRIVATE, to_fd, 0 ); 165 MAP_FILE | MAP_PRIVATE, to_fd, 0 );
164 166
165 ::memcpy(src_addr , dest_addr, stater.st_size ); 167 ::memcpy(dest_addr , src_addr, stater.st_size );
166 ::munmap(src_addr , stater.st_size ); 168 ::munmap(src_addr , stater.st_size );
167 ::munmap(dest_addr, stater.st_size ); 169 ::munmap(dest_addr, stater.st_size );
168 170
169 // done 171 // done
170} 172}