kitchensync Library API Documentation

ksharedfiledevice.cpp

00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2002 Holger Freyther <freyher@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00016 Boston, MA 02111-1307, USA. 00017 00018 */ 00019 00020 #include <kdebug.h> 00021 #include <kapplication.h> 00022 #include <qdatastream.h> 00023 #include <qcstring.h> 00024 #include <dcopclient.h> 00025 00026 #include "ksharedfiledevice.h" 00027 00028 00029 KSharedFileDevice::KSharedFileDevice() : QFile() 00030 { 00031 00032 } 00033 KSharedFileDevice::KSharedFileDevice(const QString &name ) : QFile(name ) 00034 { 00035 00036 } 00037 KSharedFileDevice::~KSharedFileDevice() 00038 { 00039 00040 } 00044 bool KSharedFileDevice::open( int mode ) 00045 { 00046 //init(); 00047 setMode( mode ); 00048 qWarning("KSharedfdileDevice::open" ); 00049 //if( mode & IO_WriteOnly || mode & IO_ReadWrite ){ qt is insane 00050 if( isWritable() || isReadWrite() ) { 00051 qWarning("ReadWrite" ); 00052 QByteArray data; 00053 QByteArray replyData; 00054 QCString replyType; 00055 QDataStream arg(data, IO_WriteOnly ); 00056 arg << name(); 00057 if(kapp->dcopClient()->call( "kded", "ksharedfile", 00058 "writeLockFile(QString)", 00059 data, 00060 replyType, replyData ) ) { 00061 QDataStream res( replyData, IO_ReadOnly ); 00062 bool ok; 00063 res >> ok; 00064 if( ok ){ 00065 if( QFile::open(mode ) ){ 00066 qWarning("open worked" ); 00067 return true; 00068 }else{ 00069 qWarning("open failed" ); 00070 return false; 00071 } 00072 }else{ 00073 kapp->dcopClient()->call( "kded", "ksharedfile", 00074 "writeUnlockFile(QString)", 00075 data, replyType, replyData); 00076 return false; 00077 } 00078 }else { 00079 return false; 00080 } 00081 }else if( isReadable() ) { 00082 qWarning("ReadOnly" ); 00083 QByteArray data; 00084 QByteArray replyData; 00085 QCString replyType; 00086 QDataStream arg(data, IO_WriteOnly ); 00087 arg << name(); 00088 if(kapp->dcopClient()->call( "kded", "ksharedfile", 00089 "readShareFile(QString)", 00090 data, 00091 replyType, replyData ) ) { 00092 QDataStream res( replyData, IO_ReadOnly ); 00093 bool ok=false; 00094 res >> ok; 00095 if( ok ){ 00096 if( QFile::open(mode ) ){ 00097 qWarning("open worked" ); 00098 return true; 00099 }else{ 00100 qWarning("hmm couldn't open" ); 00101 return false; 00102 } 00103 }else{ 00104 kapp->dcopClient()->call( "kded", "ksharedfile", 00105 "readUnshareFile(Qtring)", 00106 data, replyType, replyData); 00107 return false; 00108 } 00109 }else { 00110 return false; 00111 } 00112 } 00113 return false; 00114 } 00115 void KSharedFileDevice::close( ) 00116 { 00117 if(!isOpen() ) 00118 return; 00119 qWarning("KSharedDevice::close %s", name().latin1() ); 00120 if( isWritable() || isReadWrite() ){ 00121 QByteArray data; 00122 QByteArray replyData; 00123 QCString replyType; 00124 QDataStream arg(data, IO_WriteOnly ); 00125 arg << name(); 00126 kapp->dcopClient()->call( "kded", "ksharedfile", 00127 "writeUnlockFile(QString)", 00128 data, 00129 replyType, replyData ); 00130 }else{ 00131 QByteArray data; 00132 QByteArray replyData; 00133 QCString replyType; 00134 QDataStream arg(data, IO_WriteOnly ); 00135 arg << name(); 00136 kapp->dcopClient()->call( "kded", "ksharedfile", 00137 "readUnshareFile(QString)", 00138 data, 00139 replyType, replyData ); 00140 } 00141 } 00142 00143
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003