include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDE_DIR})
include(${QT_USE_FILE})
if(CMAKE_BUILD_TYPE STREQUAL Debug)
- message(STATUS "Debugging mode is being enabled. This is not recommended for normal use.")
- add_definitions(-DDEBUG)
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
+ message(STATUS "Debugging mode is being enabled. This is not recommended for normal use.")
+ add_definitions(-DDEBUG)
+ set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
endif(CMAKE_BUILD_TYPE STREQUAL Debug)
#No mocs
set(main main.cxx settings.cxx)
set(validator
- validator/ipaddressvalidator.cxx
- )
+ validator/ipaddressvalidator.cxx
+ )
set(ported_rmd6
- ported_rmd6/basis.cxx
- ported_rmd6/context.cxx
- ported_rmd6/rmd6.cxx
- ported_rmd6/rmd6_context.cxx
- )
+ ported_rmd6/basis.cxx
+ ported_rmd6/context.cxx
+ ported_rmd6/rmd6.cxx
+ ported_rmd6/rmd6_context.cxx
+ )
set(structures
- structures/header.cxx
- settings.cxx
- )
+ structures/header.cxx
+ settings.cxx
+ )
#Mocs
set(network_h
- network/tcpnetwork.h
+ network/tcpnetwork.h
)
set(ui_h
- ui/about.h
- ui/editdelegate.h
- ui/jasmine_mainwindow.h
- ui/memberlist.h
- ui/settingdialog.h
- ui/rtfeditor.h
+ ui/about.h
+ ui/editdelegate.h
+ ui/jasmine_mainwindow.h
+ ui/memberlist.h
+ ui/settingdialog.h
+ ui/rtfeditor.h
)
#set(file_h file/qtlockedfile.h)
#Ui files
set(ui
- ui/uifiles/about.ui
- ui/uifiles/jasmine_main.ui
- ui/uifiles/settings.ui
- )
+ ui/uifiles/about.ui
+ ui/uifiles/jasmine_main.ui
+ ui/uifiles/settings.ui
+ )
#The implementation files
set(network_src
- network/tcpnetwork.cxx
+ network/tcpnetwork.cxx
)
set(ui_src
- ui/about.cxx
- ui/editdelegate.cxx
- ui/jasmine_mainwindow.cxx
- ui/memberlist.cxx
- ui/settingdialog.cxx
- ui/rtfeditor.cxx
+ ui/about.cxx
+ ui/editdelegate.cxx
+ ui/jasmine_mainwindow.cxx
+ ui/memberlist.cxx
+ ui/settingdialog.cxx
+ ui/rtfeditor.cxx
)
set(file_impl file/qtlockedfile.cxx)
set(file_win32 file/qtlockedfile_win.cxx)
qt4_wrap_ui(ui_moc ${ui})
qt4_add_resources(res_moc ${res})
if(WIN32)
- if(OPENMP_FOUND)
- add_executable(jasmine WIN32
- ${main} ${ui_moc} ${ui_src} ${network_moc}
- ${network_src} ${structures} ${res_moc}
- ${validator} ${ported_rmd6} ${file_win32}
- ${file_impl})
- set_property(TARGET jasmine PROPERTY COMPLILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
- target_link_libraries(jasmine gomp ${QT_LIBRARIES})
- else(OPENMP_FOUND)
- add_executable(jasmine WIN32
- ${main} ${ui_moc} ${ui_src} ${network_moc}
- ${network_src} ${structures} ${res_moc}
- ${validator} ${ported_rmd6} ${file_win32} ${file_impl})
- target_link_libraries(jasmine ${QT_LIBRARIES})
- endif(OPENMP_FOUND)
+ if(OPENMP_FOUND)
+ add_executable(jasmine WIN32
+ ${main} ${ui_moc} ${ui_src} ${network_moc}
+ ${network_src} ${structures} ${res_moc}
+ ${validator} ${ported_rmd6} ${file_win32}
+ ${file_impl})
+ set_property(TARGET jasmine PROPERTY COMPILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
+ target_link_libraries(jasmine gomp ${QT_LIBRARIES})
+ else(OPENMP_FOUND)
+ add_executable(jasmine WIN32
+ ${main} ${ui_moc} ${ui_src} ${network_moc}
+ ${network_src} ${structures} ${res_moc}
+ ${validator} ${ported_rmd6} ${file_win32} ${file_impl})
+ target_link_libraries(jasmine ${QT_LIBRARIES})
+ endif(OPENMP_FOUND)
else(WIN32)
- add_library(qripemd160 SHARED ${ported_rmd6})
- add_library(validator SHARED ${validator})
- add_library(resource SHARED ${res_moc})
- add_library(structures SHARED ${structures})
+ add_library(qripemd160 SHARED ${ported_rmd6})
+ add_library(validator SHARED ${validator})
+ add_library(resource SHARED ${res_moc})
+ add_library(structures SHARED ${structures})
- add_library(network SHARED ${network_moc} ${network_src})
- add_library(ui SHARED ${ui_moc} ${ui_src})
- add_library(file SHARED ${file_unix} ${file_impl})
+ add_library(network SHARED ${network_moc} ${network_src})
+ add_library(ui SHARED ${ui_moc} ${ui_src})
+ add_library(file SHARED ${file_unix} ${file_impl})
- add_executable(jasmine ${main})
+ add_executable(jasmine ${main})
- target_link_libraries(qripemd160 ${QT_LIBRARIES})
- target_link_libraries(validator ${QT_LIBRARIES})
- target_link_libraries(resource ${QT_LIBRARIES})
- target_link_libraries(structures ${QT_LIBRARIES})
- target_link_libraries(file ${QT_LIBRARIES})
+ target_link_libraries(qripemd160 ${QT_LIBRARIES})
+ target_link_libraries(validator ${QT_LIBRARIES})
+ target_link_libraries(resource ${QT_LIBRARIES})
+ target_link_libraries(structures ${QT_LIBRARIES})
+ target_link_libraries(file ${QT_LIBRARIES})
- target_link_libraries(structures qripemd160 ${QT_LIBRARIES})
- target_link_libraries(network structures validator file ${QT_LIBRARIES})
- target_link_libraries(ui resource network file ${QT_LIBRARIES})
+ target_link_libraries(structures qripemd160 ${QT_LIBRARIES})
+ target_link_libraries(network structures validator file ${QT_LIBRARIES})
+ target_link_libraries(ui resource network file ${QT_LIBRARIES})
- target_link_libraries(jasmine ui ${QT_LIBRARIES})
- if(OPENMP_FOUND)
- set_property(TARGET ui PROPERTY COMPILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
- #set_property(TARGET network PROPERTY COMPLE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
- target_link_libraries(ui gomp)
- endif(OPENMP_FOUND)
+ target_link_libraries(jasmine ui ${QT_LIBRARIES})
+ if(OPENMP_FOUND)
+ set_property(TARGET ui PROPERTY COMPILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
+ #set_property(TARGET network PROPERTY COMPLE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
+ target_link_libraries(ui gomp)
+ endif(OPENMP_FOUND)
endif(WIN32)
qWarning("QtLockedFile::lock(): file is not opened");
return false;
}
-
+
if (mode == NoLock)
return unlock();
-
+
if (mode == m_lock_mode)
return true;
Non_public_body(QObject::tr("This software is not public version. So, please note that many bugs may exist and many features are not implemented."));
int main(int argc,char* argv[]){
- QApplication app(argc,argv);
- app.setApplicationName("jasmine");
- app.setApplicationVersion(QString("Gen.%1 Rev.%2").arg(gen).arg(rev));
- QTranslator translator;
- translator.load(app.applicationName()+"-"+QLocale::system().name(),qApp->applicationDirPath()+"/translators");
- app.installTranslator(&translator);
- mainWindow window;
- if(rev==0) QMessageBox::warning(NULL,Non_public_title,Non_public_body);
- QFileInfo memberlist(default_memberlist),setting(default_setting);
- if(setting.exists()){
- window.openConfig(default_setting);
- if(memberlist.exists()&&!window.app_setting().noloadMemberList()) window.openMember(default_memberlist);
- }
- window.show();
- return app.exec();
+ QApplication app(argc,argv);
+ app.setApplicationName("jasmine");
+ app.setApplicationVersion(QString("Gen.%1 Rev.%2").arg(gen).arg(rev));
+ QTranslator translator;
+ translator.load(app.applicationName()+"-"+QLocale::system().name(),qApp->applicationDirPath()+"/translators");
+ app.installTranslator(&translator);
+ mainWindow window;
+ if(rev==0) QMessageBox::warning(NULL,Non_public_title,Non_public_body);
+ QFileInfo memberlist(default_memberlist),setting(default_setting);
+ if(setting.exists()){
+ window.openConfig(default_setting);
+ if(memberlist.exists()&&!window.app_setting().noloadMemberList()) window.openMember(default_memberlist);
+ }
+ window.show();
+ return app.exec();
}
using namespace enc_hash;
using namespace structures;
using namespace std;
+
+//Tpc server implementation
tcpServer::tcpServer(quint64 buffersize, QObject *parent):QTcpServer(parent){this->buffersize=buffersize;}
void tcpServer::incomingConnection(int handle){
- tcpSocket *socket=new tcpSocket(this->buffersize,this);
- if(!socket->setSocketDescriptor(handle)){
- emit this->socket_error(*socket);
- return;
- }
- if(emit this->pending(*socket)) this->newConnection();
- else socket->abort();
-}
-
-threadedTcpSocket::threadedTcpSocket(int descriptor, quint64 buffersize, QObject *parent):QThread(parent){
- this->handle=descriptor;
- this->buffersize=buffersize;
- this->mode=threadedTcpSocket::receive;
- this->locker=new QReadWriteLock(QReadWriteLock::Recursive);
- this->start();
-}
-threadedTcpSocket::threadedTcpSocket(const QString &senderName, const AddressAndPort &to,quint64 buffersize, QObject *parent):QThread(parent){
- this->senderName=senderName;
- this->buffersize=buffersize;
- this->mode=threadedTcpSocket::send;
- this->to=to;
- this->locker=new QReadWriteLock(QReadWriteLock::Recursive);
- this->start();
-}
-QString threadedTcpSocket::errorString() const{
- return this->eStr;
-}
-void threadedTcpSocket::getErrorStringAndEmitError(const QAbstractSocket::SocketError &error){
- tcpSocket *socket=qobject_cast<tcpSocket *>(this->sender());
- this->eStr=socket->errorString();
- emit this->error(error);
+ tcpSocket *socket=new tcpSocket(this->buffersize,this);
+ if(!socket->setSocketDescriptor(handle)){
+ emit this->socket_error(*socket);
+ return;
+ }
+ if(emit this->pending(*socket)) this->newConnection();
+ else socket->abort();
}
-void threadedTcpSocket::connect_function(tcpSocket *socket){
- Qt::ConnectionType connection=Qt::BlockingQueuedConnection;
- connect(socket,SIGNAL(file_pending()),SIGNAL(file_pending()),connection);
- connect(socket,
- SIGNAL(fileStream_openFailed(const QFile::FileError &,const QString &)),
- SIGNAL(fileStream_openFailed(const QFile::FileError &,const QString &)),
- connection);
- connect(socket,SIGNAL(msg_received(const QString &)),
- SIGNAL(msg_received(const QString &)),connection);
- connect(socket,SIGNAL(file_receive_progress(const quint64)),
- SIGNAL(file_receive_progress(const quint64)),connection);
- connect(socket,SIGNAL(file_saved()),SIGNAL(file_saved()),connection);
-
- connect(socket,SIGNAL(sentData()),SIGNAL(sentData()),connection);
- connect(socket,SIGNAL(file_header_sent()),SIGNAL(file_header_sent()),connection);
- connect(socket,SIGNAL(sending_file_progress(const quint64)),
- SIGNAL(sending_file_progress(const quint64)),connection);
- connect(socket,SIGNAL(error(const QAbstractSocket::SocketError &)),
- SLOT(getErrorStringAndEmitError(const QAbstractSocket::SocketError &)),connection);
-}
-void threadedTcpSocket::run(){
- switch(this->mode){
- case threadedTcpSocket::receive:
- this->socket=new tcpSocket(this->buffersize,this);
- this->locker->lockForRead();
- this->connect_function(this->socket);
- this->locker->unlock();
- this->locker->lockForWrite();
- this->socket->setSocketDescriptor(this->handle);
- this->locker->unlock();
- break;
- case threadedTcpSocket::send:
- this->socket=new tcpSocket(this->senderName,this->buffersize,this);
- this->locker->lockForRead();
- this->connect_function(this->socket);
- this->locker->unlock();
- break;
- case threadedTcpSocket::send_msg:
- this->locker->lockForWrite();
- (*this->socket)<<this->msg;
- this->locker->unlock();
- break;
- case threadedTcpSocket::send_file:
- this->locker->lockForWrite();
- (*this->socket)<<this->file;
- this->locker->unlock();
- break;
- }
-}
-threadedTcpSocket &threadedTcpSocket::operator<<(const QString &msg){
- this->msg=msg;
- this->mode=threadedTcpSocket::send_msg;
- this->start();
-return (*this);
+//Tcp socket implementation
+tcpSocket::tcpSocket(const quint64 buffersize, QObject *parent):QTcpSocket(parent){
+ this->buffer_size=buffersize;
+ this->canceled=false;
+ this->event=tcpSocket::headsize;
+ connect(this,SIGNAL(disconnected()),SLOT(deleteLater()));
+ connect(this,SIGNAL(readyRead()),SLOT(read_data()));
+#ifdef DEBUG
+ qDebug()<<"TcpSocket is constructed.";
+ qDebug()<<"Status:";
+ qDebug()<<"Blocked:"<<this->signalsBlocked();
+#endif
}
-threadedTcpSocket &threadedTcpSocket::operator<<(const QFileInfo &file){
- this->file=file;
- this->mode=threadedTcpSocket::send_file;
- this->start();
- return (*this);
+tcpSocket::tcpSocket(const QString &senderName,const quint64 buffersize,QObject *parent):QTcpSocket(parent){
+ this->buffer_size=buffersize;
+ this->senderName=senderName;
}
-tcpSocket::tcpSocket(quint64 buffersize, QObject *parent):QTcpSocket(parent){
- this->buffer_size=buffersize;
- this->canceled=false;
- this->event=tcpSocket::headsize;
- connect(this,SIGNAL(disconnected()),SLOT(deleteLater()));
- connect(this,SIGNAL(readyRead()),SLOT(read_data()));
-}
-tcpSocket::tcpSocket(const QString &senderName,quint64 buffersize,QObject *parent):QTcpSocket(parent){
- this->buffer_size=buffersize;
- this->senderName=senderName;
-}
void tcpSocket::read_data(){
- while(this->bytesAvailable()>0){
+ while(this->bytesAvailable()>0){
#ifdef DEBUG
- qDebug()<<"Server Event Mode:"<<this->event<<"Server Available bytes:"<<this->bytesAvailable();
+ qDebug()<<"Server Event Mode:"<<this->event<<"Server Available bytes:"<<this->bytesAvailable();
#endif
- switch(this->event){
- case tcpSocket::headsize: this->size_event(); break;
- case tcpSocket::header_receive: this->header_event(); break;
- case tcpSocket::data: this->data_event(); break;
- }
- }
+ switch(this->event){
+ case tcpSocket::headsize: this->size_event(); break;
+ case tcpSocket::header_receive: this->header_event(); break;
+ case tcpSocket::msg: this->msg_event(); break;
+ case tcpSocket::file: this->file_event(); break;
+ }
+ }
}
void tcpSocket::size_event(){
- if(this->bytesAvailable()<2) return;
- char size_buf[2];
- this->read(size_buf,sizeof(size_buf));
- memcpy(&this->header_size,size_buf,
- (sizeof(quint16)>sizeof(__typeof__(size_buf)))?sizeof(quint16):sizeof(size_buf)
- );
- this->event=tcpSocket::header_receive;
+ if(this->bytesAvailable()<2) return;
+ char size_buf[2];
+ this->read(size_buf,sizeof(size_buf));
+ memcpy(&this->header_size,size_buf,
+ (sizeof(quint16)>sizeof(size_buf))?sizeof(quint16):sizeof(size_buf)
+ );
+ this->event=tcpSocket::header_receive;
}
void tcpSocket::header_event(){
- if(this->bytesAvailable()<this->header_size) return;
- else{
- QByteArray data=this->read(this->header_size);
- QDataStream datastream(data);
- datastream>>this->head_data;
- if(this->head_data==structures::header()){
- this->setErrorString(tr("The header is empty."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- this->disconnectFromHost();
- return;
- }
- if(!this->head_data.fileName().isEmpty()){
- this->where_to_save=(emit this->file_pending());
- if(this->where_to_save.isEmpty()){
- this->write(QByteArray(1,0x00));
-
- this->setErrorString(tr("The filename is empty."));
- emit this->error(QAbstractSocket::UnknownSocketError);
-
- this->disconnectFromHost();
- return;
- }
- }
- }
- this->event=tcpSocket::data;
-}
-void tcpSocket::data_event(){
- if((quint64)this->bytesAvailable()<this->header_data().datasize()) return;
+ if(this->bytesAvailable()<this->header_size) return;
+ else{
+ QByteArray data=this->read(this->header_size);
+ QDataStream datastream(data);
+ datastream>>this->head_data;
+ if(this->head_data==structures::header()){
+ this->setErrorString(tr("The header is empty."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->disconnectFromHost();
+ return;
+ }
+ if(!this->head_data.fileName().isEmpty()){
+ this->where_to_save=(emit this->file_pending());
+ if(this->where_to_save.isEmpty()){
+ this->write(QByteArray(1,0x00));
- quint64 final_readsize=this->head_data.datasize()%this->buffer_size,
- read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size;
+ this->setErrorString(tr("The filename is empty."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
- if(this->head_data.fileName().isEmpty()){
- QByteArray msg;
- for(quint64 count=0;count<read_count;count++){
- if(this->check_canceled_then_abort())return;
- msg+=this->read(this->buffer_size);
- }
- if(this->check_canceled_then_abort())return;
- msg+=this->read(final_readsize);
+ this->disconnectFromHost();
+ return;
+ }
+ }
+ }
+ if(this->head_data.fileName().isEmpty()) this->event=tcpSocket::msg;
+ else this->event=tcpSocket::file;
+}
+void tcpSocket::msg_event(){
+ if((quint64)this->bytesAvailable()<this->header_data().datasize()) return;
+ quint64 final_readsize=this->head_data.datasize()%this->buffer_size,
+ read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size;
+ QByteArray msg;
+ for(quint64 count=0;count<read_count;count++){
+ if(this->check_canceled_then_abort())return;
+ msg+=this->read(this->buffer_size);
+ }
+ if(this->check_canceled_then_abort())return;
+ msg+=this->read(final_readsize);
- rmd6 generator;
- if(this->head_data.ripemd160()==generator.compute_hash(msg))
- emit this->msg_received(QString::fromUtf8(msg.data()));
- else{
- this->setErrorString(tr("The data has been broken."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- this->disconnectFromHost();
- }
- }else{
- streamopen:
- if(this->where_to_save.isEmpty()){
- this->setErrorString(tr("The filename is empty."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- this->disconnectFromHost();
- return;
- }
- QFile file(this->where_to_save,this);
- if(!file.open(QIODevice::Truncate|QIODevice::WriteOnly)){
- this->where_to_save=emit this->fileStream_openFailed(file.error(),file.errorString());
- goto streamopen;
- }
- for(quint64 count=0;count<read_count;count++){
- if(this->check_canceled_then_abort())return;
- file.write(this->read(this->buffer_size));
- emit this->file_receive_progress(file.pos());
- }
- if(this->check_canceled_then_abort())return;
- file.write(this->read(final_readsize));
- emit this->file_receive_progress(file.pos());
- file.close();
+ rmd6 generator;
+ if(this->head_data.ripemd160()==generator.compute_hash(msg))
+ emit this->msg_received(QString::fromUtf8(msg.data()));
+ else{
+ this->setErrorString(tr("The data has been broken."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ }
+ this->disconnectFromHost();
+}
+void tcpSocket::file_event(){
+ if((quint64)this->bytesAvailable()<this->header_data().datasize()) return;
+ quint64 final_readsize=this->head_data.datasize()%this->buffer_size,
+ read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size;
+ streamopen:
+ if(this->where_to_save.isEmpty()){
+ this->setErrorString(tr("The filename is empty."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->disconnectFromHost();
+ return;
+ }
+ QFile file(this->where_to_save,this);
+ if(!file.open(QIODevice::Truncate|QIODevice::WriteOnly)){
+ this->where_to_save=emit this->fileStream_openFailed(file.error(),file.errorString());
+ goto streamopen;
+ }
+ for(quint64 count=0;count<read_count&&!this->check_canceled_then_abort();count++){
+ if(this->check_canceled_then_abort())return;
+ file.write(this->read(this->buffer_size));
+ emit this->file_receive_progress(file.pos());
+ }
+ if(this->check_canceled_then_abort())return;
+ file.write(this->read(final_readsize));
+ emit this->file_receive_progress(file.pos());
+ file.close();
- rmd6 generator;
- if(this->head_data.ripemd160()==generator.compute_hash(file))
- emit this->file_saved();
- else{
- this->setErrorString(tr("The file has been broken."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- this->disconnectFromHost();
- }
- }
- this->disconnectFromHost();
+ rmd6 generator;
+ if(this->head_data.ripemd160()==generator.compute_hash(file))
+ emit this->file_saved();
+ else{
+ this->setErrorString(tr("The file has been broken."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ }
+ this->disconnectFromHost();
}
bool tcpSocket::check_canceled_then_abort(){
- if(this->canceled){
- this->setErrorString(tr("The process has been canceled by user."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- this->abort();
- return true;
- }
- return false;
+ if(this->canceled){
+ this->setErrorString(tr("The process has been canceled by user."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->abort();
+ return true;
+ }
+ return false;
}
void tcpSocket::disconnectFromHostImplementation(){
- this->canceled=true;
- QTcpSocket::disconnectFromHost();
+ this->canceled=true;
+ QTcpSocket::disconnectFromHost();
}
tcpSocket &tcpSocket::operator<<(const QString &msg){
- if(this->state()!=QAbstractSocket::ConnectedState) return (*this);
- this->head_data=header(this->senderName,msg);
- QByteArray tmp_buffer;
- QDataStream datastream(&tmp_buffer,QIODevice::WriteOnly);
- datastream<<this->head_data;
- quint16 size=(quint16)tmp_buffer.size();
- this->write((char*)&size,sizeof(__typeof__(size))/sizeof(char));
- if(!this->flush())return (*this);
- this->write(tmp_buffer);
- if(!this->flush())return (*this);
- tmp_buffer.clear();
- tmp_buffer=msg.toUtf8();
- QBuffer memoryStream(&tmp_buffer,this);
- if(!memoryStream.open(QIODevice::ReadOnly)){
- this->setErrorString(tr("Memory Stream couldn't open."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- return (*this);
- }
- while(this->write(memoryStream.read(this->buffer_size))>0)
- if(!this->flush())return (*this);
- memoryStream.close();
+ if(this->state()!=QAbstractSocket::ConnectedState) return (*this);
+ this->head_data=header(this->senderName,msg);
+ QByteArray tmp_buffer;
+ QDataStream datastream(&tmp_buffer,QIODevice::WriteOnly);
+ datastream<<this->head_data;
+ quint16 size=(quint16)tmp_buffer.size();
+ this->write((char*)&size,sizeof(size)/sizeof(char));
+ if(!this->flush())return (*this);
+ this->write(tmp_buffer);
+ if(!this->flush())return (*this);
+ tmp_buffer.clear();
+ tmp_buffer=msg.toUtf8();
+ QBuffer memoryStream(&tmp_buffer,this);
+ if(!memoryStream.open(QIODevice::ReadOnly)){
+ this->setErrorString(tr("Memory Stream couldn't open."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ return (*this);
+ }
+ while(this->write(memoryStream.read(this->buffer_size))>0)
+ if(!this->flush())return (*this);
+ memoryStream.close();
- emit this->sentData();
- return (*this);
+ emit this->sentData();
+ return (*this);
}
tcpSocket &tcpSocket::operator<<(const QFileInfo &src_file){
- QtLockedFile file(src_file.fileName());
- if(!this->state()!=QAbstractSocket::ConnectedState)return (*this);
- this->head_data=header(this->senderName,QFileInfo(file));
- QByteArray tmp_buffer;
- QDataStream datastream(tmp_buffer);
- quint16 size=(quint16)tmp_buffer.size();
- datastream<<this->head_data;
- this->write((char*)&size,sizeof(__typeof__(size))/sizeof(char));
- if(!this->flush())return (*this);
- this->write(tmp_buffer);
- if(!this->flush())return (*this);
- tmp_buffer.clear();
- emit this->file_header_sent();
- if(!file.open(QIODevice::ReadOnly)){
- this->setErrorString(tr("The file stream couldn't open."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- return (*this);
- }
- file.lock(QtLockedFile::ReadLock);
- while(this->write(file.read(this->buffer_size))>0&&!this->check_canceled_then_abort()){
- if(!this->flush())return (*this);
- emit this->sending_file_progress(file.pos());
- }
- file.unlock();
- file.close();
- emit this->sentData();
- return (*this);
+ QtLockedFile file(src_file.fileName());
+ if(!this->state()!=QAbstractSocket::ConnectedState)return (*this);
+ this->head_data=header(this->senderName,QFileInfo(file));
+ QByteArray tmp_buffer;
+ QDataStream datastream(tmp_buffer);
+ quint16 size=(quint16)tmp_buffer.size();
+ datastream<<this->head_data;
+ this->write((char*)&size,sizeof(size)/sizeof(char));
+ if(!this->flush())return (*this);
+ this->write(tmp_buffer);
+ if(!this->flush())return (*this);
+ tmp_buffer.clear();
+ emit this->file_header_sent();
+ if(!file.open(QIODevice::ReadOnly)){
+ this->setErrorString(tr("The file stream couldn't open."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ return (*this);
+ }
+ file.lock(QtLockedFile::ReadLock);
+ while(this->write(file.read(this->buffer_size))>0&&!this->check_canceled_then_abort()){
+ if(!this->flush())return (*this);
+ emit this->sending_file_progress(file.pos());
+ }
+ file.unlock();
+ file.close();
+ emit this->sentData();
+ return (*this);
}
void tcpSocket::cancel(){this->canceled=true;}
QString tcpSocket::path_to_save() const{return this->where_to_save;}
#define default_bandwidth 0x400
namespace network{
- class tcpSocket;
+ class tcpSocket;
+ class threadedTcpSocket;
- class tcpServer:virtual public QTcpServer{
- Q_OBJECT
- public:
- tcpServer(quint64 buffersize=default_bandwidth,QObject *parent=NULL);
- signals:
- bool pending(const tcpSocket &) const;
- void socket_error(const tcpSocket &) const;
- protected:
- void incomingConnection(int handle);
- private:
- quint64 buffersize;
- };
+ class tcpServer:virtual public QTcpServer{
+ Q_OBJECT
+ public:
+ tcpServer(quint64 buffersize=default_bandwidth,QObject *parent=NULL);
+ signals:
+ bool pending(const tcpSocket &) const;
+ bool pending(const threadedTcpSocket &) const;
+ void socket_error(const tcpSocket &) const;
+ protected:
+ void incomingConnection(int handle);
+ private:
+ quint64 buffersize;
+ };
+ class tcpSocket:public QTcpSocket{
+ Q_OBJECT
+ public:
+ //This constructor is for server. it works as a session.
+ tcpSocket(const quint64 buffersize=default_bandwidth,QObject *parent=NULL);
+ //This constructor is for client. it works as a client.
+ tcpSocket(const QString &senderName,const quint64 buffersize=default_buffer_size,QObject *parent=NULL);
+ QString path_to_save() const;
+ structures::header header_data() const;
+ //Calling operator<<(QFile), the specified file stream will be copied.
+ tcpSocket &operator<<(const QString &),
+ &operator<<(const QFileInfo &);
+ signals:
+ QString file_pending() const;
+ QString fileStream_openFailed(const QFile::FileError &,const QString &) const;
- class threadedTcpSocket:virtual public QThread{
- Q_OBJECT
- public:
- //This constructor is for server. it works as a session.
- threadedTcpSocket(int,quint64 buffersize=default_bandwidth,QObject *parent=NULL);
- //This constructor is for client. it works as a client.
- threadedTcpSocket(const QString &senderName,const AddressAndPort &,quint64 buffersize=default_buffer_size,QObject *parent=NULL);
- QString errorString() const;
- threadedTcpSocket &operator<<(const QString &);
- threadedTcpSocket &operator<<(const QFileInfo &);
- //threadedTcpSocket &operator<<(QFile &);
- signals:
- QString file_pending() const;
- QString fileStream_openFailed(const QFile::FileError &,const QString &) const;
+ void msg_received(const QString &) const;
- void msg_received(const QString &) const;
+ void file_receive_progress(const quint64 streamPos) const;
+ void file_saved() const;
- void file_receive_progress(const quint64 streamPos) const;
- void file_saved() const;
-
- void sentData();
- void file_header_sent();
- void sending_file_progress(const quint64 pos);
- void error(const QAbstractSocket::SocketError &);
- private slots:
- void getErrorStringAndEmitError(const QAbstractSocket::SocketError &);
- protected:
- void run();
- private:
- void connect_function(tcpSocket *socket);
- enum Mode{receive,send,send_msg,send_file} mode;
- tcpSocket *socket;
- AddressAndPort to;
- QString senderName,eStr,msg;
- QFileInfo file;
- QReadWriteLock *locker;
- int handle;
- quint64 buffersize;
- };
-
- class tcpSocket:public QTcpSocket{
- Q_OBJECT
- public:
- //This constructor is for server. it works as a session.
- tcpSocket(quint64 buffersize=default_bandwidth,QObject *parent=NULL);
- //This constructor is for client. it works as a client.
- tcpSocket(const QString &senderName,quint64 buffersize=default_buffer_size,QObject *parent=NULL);
- QString path_to_save() const;
- structures::header header_data() const;
- //Calling operator<<(QFile), the specified file stream will be copied.
- tcpSocket &operator<<(const QString &),
- &operator<<(const QFileInfo &);
- signals:
- QString file_pending() const;
- QString fileStream_openFailed(const QFile::FileError &,const QString &) const;
-
- void msg_received(const QString &) const;
-
- void file_receive_progress(const quint64 streamPos) const;
- void file_saved() const;
-
- void sentData();
- void file_header_sent();
- void sending_file_progress(const quint64 pos);
- private slots:
- void read_data();
- void cancel();
- protected:
- void disconnectFromHostImplementation();
- private:
- enum mode{headsize,header_receive,data} event;
- void size_event();
- void header_event();
- void data_event();
- bool check_canceled_then_abort();
- //The size of header needs to be larger than 0, and smaller than or equal to 0xFFFF.
- quint16 header_size,buffer_size,timeout_time;
- structures::header head_data;
- bool canceled;
- QString where_to_save, senderName;
- };
+ void sentData();
+ void file_header_sent();
+ void sending_file_progress(const quint64 pos);
+ private slots:
+ void read_data();
+ void cancel();
+ protected:
+ void disconnectFromHostImplementation();
+ private:
+ enum mode{headsize,header_receive,msg,file} event;
+ void size_event();
+ void header_event();
+ void msg_event();
+ void file_event();
+ bool check_canceled_then_abort();
+ //The size of header needs to be larger than 0, and smaller than or equal to 0xFFFF.
+ quint16 header_size,buffer_size,timeout_time;
+ structures::header head_data;
+ bool canceled;
+ QString where_to_save, senderName;
+ };
}
using namespace enc_hash::inside;
quint32 hash_basis::left_rol(const quint32 &x,const quint32 &n)const{return ((x<<n)|(x>>(32-n)));}
QVector<quint32> hash_basis::__compute_hash(context_basis &context,const QByteArray &str){
- const quint32 *msg=(const quint32 *)str.data();
- context.len[0]=str.size();
- for(quint32 size=str.size();size>63;size-=64,msg+=16){
- memcpy(context.X,msg,sizeof(context.X));
- this->compress(context);
- }
- this->finish(context,msg);
- return context.buf;
+ const quint32 *msg=(const quint32 *)str.data();
+ context.len[0]=str.size();
+ for(quint32 size=str.size();size>63;size-=64,msg+=16){
+ memcpy(context.X,msg,sizeof(context.X));
+ this->compress(context);
+ }
+ this->finish(context,msg);
+ return context.buf;
}
QVector<quint32> hash_basis::__compute_hash(context_basis &context,QIODevice &stream){
- if((!stream.isOpen()&&!stream.open(QIODevice::ReadOnly))||!stream.isReadable())
- return QVector<quint32>(5);
- quint32 index,pos=stream.pos();
- QByteArray data;
- while(!stream.atEnd()){
- data=stream.read(0x100);
- for(quint32 i=0;i<(data.size()>>6);i++){
- memcpy(context.X,((quint32*)data.data())+(16*i),sizeof(context.X));
- this->compress(context);
- }
- if(context.len[0]+data.size()<context.len[0]) context.len[1]++;
- context.len[0]+=data.size();
- }
- //Take modulo 64*15
- index=(context.len[0]&0x3c0)>>2;
+ if((!stream.isOpen()&&!stream.open(QIODevice::ReadOnly))||!stream.isReadable())
+ return QVector<quint32>(5);
+ quint32 index,pos=stream.pos();
+ QByteArray data;
+ while(!stream.atEnd()){
+ data=stream.read(0x100);
+ for(quint32 i=0;i<(data.size()>>6);i++){
+ memcpy(context.X,((quint32*)data.data())+(16*i),sizeof(context.X));
+ this->compress(context);
+ }
+ if(context.len[0]+data.size()<context.len[0]) context.len[1]++;
+ context.len[0]+=data.size();
+ }
+ //Take modulo 64*15
+ index=(context.len[0]&0x3c0)>>2;
- this->finish(context,((quint32*)data.data())+index);
- stream.seek(pos);
- return context.buf;
+ this->finish(context,((quint32*)data.data())+index);
+ stream.seek(pos);
+ return context.buf;
}
void hash_basis::finish(context_basis &context,const quint32 *str){
- memset(context.X,0,sizeof(context.X));
- quint32 len64=context.len[0]&63;
- memcpy(context.X,str,len64);
- context.X[(context.len[0]>>2)&15]^=(uint)1<<(8*(context.len[0]&3)+7);
- if(len64>55){
- this->compress(context);
- memset(context.X,0,sizeof(context.X));
- }
- context.X[14]=context.len[0]<<3;
- context.X[15]=(context.len[0]>>29)|(context.len[1]<<3);
- this->compress(context);
+ memset(context.X,0,sizeof(context.X));
+ quint32 len64=context.len[0]&63;
+ memcpy(context.X,str,len64);
+ context.X[(context.len[0]>>2)&15]^=(uint)1<<(8*(context.len[0]&3)+7);
+ if(len64>55){
+ this->compress(context);
+ memset(context.X,0,sizeof(context.X));
+ }
+ context.X[14]=context.len[0]<<3;
+ context.X[15]=(context.len[0]>>29)|(context.len[1]<<3);
+ this->compress(context);
}
#include <cstring>
#include "context.h"
namespace enc_hash{
- namespace inside{
- class hash_basis{
- protected:
- quint32 left_rol(const quint32 &x,const quint32 &n)const;
- void left_rol_block(quint32 *array,quint32 blocksize,const quint32 n)const{
- for(quint32 c=0;c<n;c++){
- quint32 tmp=array[blocksize-1];
- for(ushort i=(blocksize-1);i>0;i--) array[i]=array[i-1];
- array[0]=tmp;
- }
- }
- QVector<quint32> __compute_hash(context_basis &context,const QByteArray &str);
- QVector<quint32> __compute_hash(context_basis &context,QIODevice &stream);
- virtual void compress(context_basis &context)=0;
- void finish(context_basis &context,const quint32 *str);
- };
- }
+ namespace inside{
+ class hash_basis{
+ protected:
+ quint32 left_rol(const quint32 &x,const quint32 &n)const;
+ void left_rol_block(quint32 *array,quint32 blocksize,const quint32 n)const{
+ for(quint32 c=0;c<n;c++){
+ quint32 tmp=array[blocksize-1];
+ for(ushort i=(blocksize-1);i>0;i--) array[i]=array[i-1];
+ array[0]=tmp;
+ }
+ }
+ QVector<quint32> __compute_hash(context_basis &context,const QByteArray &str);
+ QVector<quint32> __compute_hash(context_basis &context,QIODevice &stream);
+ virtual void compress(context_basis &context)=0;
+ void finish(context_basis &context,const quint32 *str);
+ };
+ }
}
#include"context.h"
using namespace enc_hash::inside;
context_basis::context_basis(){
- memset(this->X,0,sizeof(this->X));
- memset(this->len,0,sizeof(this->len));
+ memset(this->X,0,sizeof(this->X));
+ memset(this->len,0,sizeof(this->len));
}
#include<sys/types.h>
using namespace std;
namespace enc_hash{
- namespace inside{
- class context_basis{
- public:
- QVector<quint32> buf;
- quint32 len[2],X[16];
- context_basis();
- };
- }
+ namespace inside{
+ class context_basis{
+ public:
+ QVector<quint32> buf;
+ quint32 len[2],X[16];
+ context_basis();
+ };
+ }
}
#include"rmd6.h"
using namespace enc_hash;
QVector<quint32> rmd6::compute_hash(const QByteArray &str){
- rmd6_context context;
- return this->__compute_hash(context,str);
+ rmd6_context context;
+ return this->__compute_hash(context,str);
}
QVector<quint32> rmd6::compute_hash(QIODevice &stream){
- rmd6_context context;
- return this->__compute_hash(context,stream);
+ rmd6_context context;
+ return this->__compute_hash(context,stream);
}
quint32 rmd6::f1(const quint32 *xyz) const{return (xyz[0]^xyz[1]^xyz[2]);}
quint32 rmd6::f2(const quint32 *xyz) const{return (xyz[0]&xyz[1])|(~xyz[0]&xyz[2]);}
quint32 rmd6::f4(const quint32 *xyz) const{return (xyz[0]&xyz[2])|(xyz[1]&~xyz[2]);}
quint32 rmd6::f5(const quint32 *xyz) const{return xyz[0]^(xyz[1]|~xyz[2]);}
void rmd6::left(quint32 *buf,const quint32 &x,const quint32 &s,const quint32 round)const{
- const quint32 constants[]={0,0x5a827999UL,0x6ed9eba1UL,0x8f1bbcdcUL,0xa953fd4eUL};
- switch(round){
- case 0: buf[0]=this->left_rol(buf[0]+this->f1(buf+1)+x+constants[round],s)+buf[4];break;
- case 1: buf[0]=this->left_rol(buf[0]+this->f2(buf+1)+x+constants[round],s)+buf[4];break;
- case 2: buf[0]=this->left_rol(buf[0]+this->f3(buf+1)+x+constants[round],s)+buf[4];break;
- case 3: buf[0]=this->left_rol(buf[0]+this->f4(buf+1)+x+constants[round],s)+buf[4];break;
- case 4: buf[0]=this->left_rol(buf[0]+this->f5(buf+1)+x+constants[round],s)+buf[4];break;
- }
- buf[2]=this->left_rol(buf[2],10);
+ const quint32 constants[]={0,0x5a827999UL,0x6ed9eba1UL,0x8f1bbcdcUL,0xa953fd4eUL};
+ switch(round){
+ case 0: buf[0]=this->left_rol(buf[0]+this->f1(buf+1)+x+constants[round],s)+buf[4];break;
+ case 1: buf[0]=this->left_rol(buf[0]+this->f2(buf+1)+x+constants[round],s)+buf[4];break;
+ case 2: buf[0]=this->left_rol(buf[0]+this->f3(buf+1)+x+constants[round],s)+buf[4];break;
+ case 3: buf[0]=this->left_rol(buf[0]+this->f4(buf+1)+x+constants[round],s)+buf[4];break;
+ case 4: buf[0]=this->left_rol(buf[0]+this->f5(buf+1)+x+constants[round],s)+buf[4];break;
+ }
+ buf[2]=this->left_rol(buf[2],10);
}
void rmd6::right(quint32 *buf,const quint32 &x,const quint32 &s,const quint32 round) const{
- const quint32 constants[]={0x50a28be6UL,0x5c4dd124UL,0x6d703ef3UL,0x7a6d76e9UL,0};
- switch(round){
- case 0: buf[0]=this->left_rol(buf[0]+this->f5(buf+1)+x+constants[round],s)+buf[4];break;
- case 1: buf[0]=this->left_rol(buf[0]+this->f4(buf+1)+x+constants[round],s)+buf[4];break;
- case 2: buf[0]=this->left_rol(buf[0]+this->f3(buf+1)+x+constants[round],s)+buf[4];break;
- case 3: buf[0]=this->left_rol(buf[0]+this->f2(buf+1)+x+constants[round],s)+buf[4];break;
- case 4: buf[0]=this->left_rol(buf[0]+this->f1(buf+1)+x+constants[round],s)+buf[4];break;
- }
- buf[2]=this->left_rol(buf[2],10);
+ const quint32 constants[]={0x50a28be6UL,0x5c4dd124UL,0x6d703ef3UL,0x7a6d76e9UL,0};
+ switch(round){
+ case 0: buf[0]=this->left_rol(buf[0]+this->f5(buf+1)+x+constants[round],s)+buf[4];break;
+ case 1: buf[0]=this->left_rol(buf[0]+this->f4(buf+1)+x+constants[round],s)+buf[4];break;
+ case 2: buf[0]=this->left_rol(buf[0]+this->f3(buf+1)+x+constants[round],s)+buf[4];break;
+ case 3: buf[0]=this->left_rol(buf[0]+this->f2(buf+1)+x+constants[round],s)+buf[4];break;
+ case 4: buf[0]=this->left_rol(buf[0]+this->f1(buf+1)+x+constants[round],s)+buf[4];break;
+ }
+ buf[2]=this->left_rol(buf[2],10);
}
void rmd6::compress(context_basis &context){
- quint32 np_buf[5],p_buf[5];
- //Iterator cannot use memcpy. Instead, for loop is used.
- for(quint32 counter=0;counter<5;counter++){
- p_buf[counter]=context.buf[counter];
- np_buf[counter]=context.buf[counter];
- }
- quint32 np_i[]={
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
- 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
- 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
- 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
- },
- np_s[]={
- 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
- 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
- 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
- 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
- 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
- },
- p_i[]={
- 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
- 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
- 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
- 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
- 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
- },
- p_s[]={
- 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
- 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
- 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
- 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
- 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
- };
- for(quint32 count=0,round=0;count<80;count++,round=count>>4){
- this->left(np_buf,context.X[np_i[count]],np_s[count],round);
- this->right(p_buf,context.X[p_i[count]],p_s[count],round);
- left_rol_block(np_buf,5,1);
- left_rol_block(p_buf,5,1);
- }
- p_buf[3]+=np_buf[2]+context.buf[1];
- for(quint16 i=1;i<5;i++) context.buf[i]=context.buf[(i+1)%5]+np_buf[(i+2)%5]+p_buf[(i+3)%5];
- context.buf[0]=p_buf[3];
+ quint32 np_buf[5],p_buf[5];
+ //Iterator cannot use memcpy. Instead, for loop is used.
+ for(quint32 counter=0;counter<5;counter++){
+ p_buf[counter]=context.buf[counter];
+ np_buf[counter]=context.buf[counter];
+ }
+ quint32 np_i[]={
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
+ 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
+ 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
+ 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
+ },
+ np_s[]={
+ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
+ 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
+ 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
+ 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
+ 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
+ },
+ p_i[]={
+ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
+ 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
+ 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
+ 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
+ 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
+ },
+ p_s[]={
+ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
+ 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
+ 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
+ 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
+ 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
+ };
+ for(quint32 count=0,round=0;count<80;count++,round=count>>4){
+ this->left(np_buf,context.X[np_i[count]],np_s[count],round);
+ this->right(p_buf,context.X[p_i[count]],p_s[count],round);
+ left_rol_block(np_buf,5,1);
+ left_rol_block(p_buf,5,1);
+ }
+ p_buf[3]+=np_buf[2]+context.buf[1];
+ for(quint16 i=1;i<5;i++) context.buf[i]=context.buf[(i+1)%5]+np_buf[(i+2)%5]+p_buf[(i+3)%5];
+ context.buf[0]=p_buf[3];
}
using namespace std;
using namespace enc_hash::inside;
namespace enc_hash{
- class rmd6:virtual public inside::hash_basis{
- public:
- QVector<quint32> compute_hash(const QByteArray &str);
- QVector<quint32> compute_hash(QIODevice &stream);
- private:
- quint32 f1(const quint32 *xyz) const;
- quint32 f2(const quint32 *xyz) const;
- quint32 f3(const quint32 *xyz) const;
- quint32 f4(const quint32 *xyz) const;
- quint32 f5(const quint32 *xyz) const;
- void left(quint32 *buf,const quint32 &x,const quint32 &s,const quint32 round) const ;
- void right(quint32 *buf,const quint32 &x,const quint32 &s,const quint32 round) const;
- void compress(context_basis &context);
- };
+ class rmd6:virtual public inside::hash_basis{
+ public:
+ QVector<quint32> compute_hash(const QByteArray &str);
+ QVector<quint32> compute_hash(QIODevice &stream);
+ private:
+ quint32 f1(const quint32 *xyz) const;
+ quint32 f2(const quint32 *xyz) const;
+ quint32 f3(const quint32 *xyz) const;
+ quint32 f4(const quint32 *xyz) const;
+ quint32 f5(const quint32 *xyz) const;
+ void left(quint32 *buf,const quint32 &x,const quint32 &s,const quint32 round) const ;
+ void right(quint32 *buf,const quint32 &x,const quint32 &s,const quint32 round) const;
+ void compress(context_basis &context);
+ };
}
#include"rmd6_context.h"
using namespace enc_hash::inside;
rmd6_context::rmd6_context(){
- QVector<quint32> init_buf(5);
- init_buf[0]=(quint32)0x67452301;
- init_buf[1]=(quint32)0xefcdab89;
- init_buf[2]=(quint32)0x98badcfe;
- init_buf[3]=(quint32)0x10325476;
- init_buf[4]=(quint32)0xc3d2e1f0;
- this->buf=init_buf;
+ QVector<quint32> init_buf(5);
+ init_buf[0]=(quint32)0x67452301;
+ init_buf[1]=(quint32)0xefcdab89;
+ init_buf[2]=(quint32)0x98badcfe;
+ init_buf[3]=(quint32)0x10325476;
+ init_buf[4]=(quint32)0xc3d2e1f0;
+ this->buf=init_buf;
}
#include"context.h"
using namespace std;
namespace enc_hash{
- namespace inside{
- class rmd6_context:virtual public context_basis{
- public:
- rmd6_context();
- };
- }
+ namespace inside{
+ class rmd6_context:virtual public context_basis{
+ public:
+ rmd6_context();
+ };
+ }
}
using namespace structures;
settings::settings():_name(QObject::tr("Anonymouse")),_bindingAddr(QHostAddress(QHostAddress::Any)),_port(10630),_noloadmember(false){}
settings::settings(const QString &name,const QHostAddress address,
- const quint16 port,const bool noloadMember):_name(name),_bindingAddr(address),_port(port),_noloadmember(noloadMember){}
+ const quint16 port,const bool noloadMember):_name(name),_bindingAddr(address),_port(port),_noloadmember(noloadMember){}
void settings::setName(const QString &name){this->_name=name;}
void settings::setIPAddr(const QHostAddress &address){this->_bindingAddr=address;}
#include <QtCore>
#include <QHostAddress>
namespace structures{
- class settings{
- public:
- settings();
- settings(const QString &name,const QHostAddress address=QHostAddress(QHostAddress::Any),const quint16 port=10630,const bool noloadMember=false);
- void setName(const QString &name),
- setIPAddr(const QHostAddress &address),
- setPort(const quint16 port),
- setFileName(const QString &name),
- setNoloadMemberList(const bool yesno);
- QString name()const;
- QHostAddress bindingAddr()const;
- quint16 port()const;
- bool noloadMemberList()const;
- friend QDataStream &operator<<(QDataStream &out,const settings &value){
- out<<value._port<<value._bindingAddr<<value._name<<value._noloadmember;
- return out;
- }
- friend QDataStream &operator>>(QDataStream &in,settings &value){
- in>>value._port>>value._bindingAddr>>value._name<<value._noloadmember;
- return in;
- }
- private:
- QString _name;
- QHostAddress _bindingAddr;
- quint16 _port;
- bool _noloadmember;
- };
+ class settings{
+ public:
+ settings();
+ settings(const QString &name,const QHostAddress address=QHostAddress(QHostAddress::Any),const quint16 port=10630,const bool noloadMember=false);
+ void setName(const QString &name),
+ setIPAddr(const QHostAddress &address),
+ setPort(const quint16 port),
+ setFileName(const QString &name),
+ setNoloadMemberList(const bool yesno);
+ QString name()const;
+ QHostAddress bindingAddr()const;
+ quint16 port()const;
+ bool noloadMemberList()const;
+ friend QDataStream &operator<<(QDataStream &out,const settings &value){
+ out<<value._port<<value._bindingAddr<<value._name<<value._noloadmember;
+ return out;
+ }
+ friend QDataStream &operator>>(QDataStream &in,settings &value){
+ in>>value._port>>value._bindingAddr>>value._name<<value._noloadmember;
+ return in;
+ }
+ private:
+ QString _name;
+ QHostAddress _bindingAddr;
+ quint16 _port;
+ bool _noloadmember;
+ };
}
using namespace structures;
using namespace enc_hash;
header::header():rmd6_hash(5){}
-header::header(const QString &senderName,const QString &msg):
- sendername(senderName),data_size(msg.size()){
- rmd6 gen;
- this->rmd6_hash=gen.compute_hash(msg.toUtf8());
+header::header(const QString &senderName,const QString &msg): sendername(senderName),data_size(msg.size()){
+ rmd6 gen;
+ this->rmd6_hash=gen.compute_hash(msg.toUtf8());
}
header::header(const QString &senderName,const QFileInfo &fileinfo):
- filename(fileinfo.completeBaseName()),sendername(senderName),
- data_size(fileinfo.size()),rmd6_hash(5){
- rmd6 gen;
- QFile dev(fileinfo.absoluteFilePath());
- if(!dev.open(QFile::ReadOnly)) return;
- this->rmd6_hash=gen.compute_hash(dev);
+ filename(fileinfo.completeBaseName()),sendername(senderName),
+ data_size(fileinfo.size()),rmd6_hash(5){
+ rmd6 gen;
+ QFile dev(fileinfo.absoluteFilePath());
+ if(!dev.open(QFile::ReadOnly)) return;
+ this->rmd6_hash=gen.compute_hash(dev);
}
QString header::senderName()const{return this->sendername;}
void header::fileName(const QString &filename){this->filename=filename;}
void header::datasize(const quint64 size){this->data_size=size;}
bool header::operator==(const header &head) const{
- return (this->sendername==head.senderName()&&
- this->filename==head.fileName()&&
- this->data_size==head.datasize()&&
- this->rmd6_hash==head.ripemd160());
+ return (this->sendername==head.senderName()&&
+ this->filename==head.fileName()&&
+ this->data_size==head.datasize()&&
+ this->rmd6_hash==head.ripemd160());
}
bool header::operator!=(const header &head) const{
- return (this->sendername!=head.senderName()||
- this->filename !=head.fileName()||
- this->data_size !=head.datasize()||
- this->rmd6_hash !=head.ripemd160());
+ return (this->sendername!=head.senderName()||
+ this->filename !=head.fileName()||
+ this->data_size !=head.datasize()||
+ this->rmd6_hash !=head.ripemd160());
}
#pragma once
#include <QtCore>
namespace structures{
- class header{
- public:
- header();
- header(const QString &senderName,const QFileInfo &fileinfo);
- header(const QString &senderName,const QString &msg);
- QString fileName()const,
- senderName()const;
- quint64 datasize()const;
- QVector<quint32> ripemd160() const;
- bool operator==(const header &) const;
- bool operator!=(const header &) const;
- friend QDataStream &operator<<(QDataStream &out,const header &value){
- out<<value.data_size<<value.rmd6_hash<<value.sendername<<value.filename;
- return out;
- }
- friend QDataStream &operator>>(QDataStream &in,header &value){
- in>>value.data_size>>value.rmd6_hash>>value.sendername>>value.filename;
- return in;
- }
+ class header{
+ public:
+ header();
+ header(const QString &senderName,const QFileInfo &fileinfo);
+ header(const QString &senderName,const QString &msg);
+ QString fileName()const,
+ senderName()const;
+ quint64 datasize()const;
+ QVector<quint32> ripemd160() const;
+ bool operator==(const header &) const;
+ bool operator!=(const header &) const;
+ friend QDataStream &operator<<(QDataStream &out,const header &value){
+ out<<value.data_size<<value.rmd6_hash<<value.sendername<<value.filename;
+ return out;
+ }
+ friend QDataStream &operator>>(QDataStream &in,header &value){
+ in>>value.data_size>>value.rmd6_hash>>value.sendername>>value.filename;
+ return in;
+ }
- void senderName(const QString &),
- datasize(const quint64),
- fileName(const QString &);
+ void senderName(const QString &),
+ datasize(const quint64),
+ fileName(const QString &);
- private:
- QString filename,sendername;
- quint64 data_size;
- QVector<quint32> rmd6_hash;
- };
+ private:
+ QString filename,sendername;
+ quint64 data_size;
+ QVector<quint32> rmd6_hash;
+ };
}
#include "../app_version.h"
about::about(QWidget *parent):QDialog(parent){
- setupUi(this);
- this->setMinimumSize(this->size());
- this->setMaximumSize(this->size());
- this->version_body=tr("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">"
- "<html>"
- "<head>"
- "</head>"
- "<body>"
- "<p>Generation:%1<br />Revision:%2</p>"
- "<p>Author:<br />"
- "<a href=\"http://hysoftware.net/\">Hiroaki Yamamoto</a></p>"
- "<p>This software is being distributed under the terms of the latest version of The GNU General Public License(GPL). You can copy this software, modify it, and/or redistribute it. However, In order to redistribute this software, releasing its sourcecode is needed.</p>"
- "<p>I'll welcome bug reports. If you found bugs, please let me know.</p></body></html>");
- this->versiontext->setHtml(this->version_body);
- this->setVersion(gen,rev);
+ setupUi(this);
+ this->setMinimumSize(this->size());
+ this->setMaximumSize(this->size());
+ this->version_body=tr("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">"
+ "<html>"
+ "<head>"
+ "</head>"
+ "<body>"
+ "<p>Generation:%1<br />Revision:%2</p>"
+ "<p>Author:<br />"
+ "<a href=\"http://hysoftware.net/\">Hiroaki Yamamoto</a></p>"
+ "<p>This software is being distributed under the terms of the latest version of The GNU General Public License(GPL). You can copy this software, modify it, and/or redistribute it. However, In order to redistribute this software, releasing its sourcecode is needed.</p>"
+ "<p>I'll welcome bug reports. If you found bugs, please let me know.</p></body></html>");
+ this->versiontext->setHtml(this->version_body);
+ this->setVersion(gen,rev);
}
void about::setGenVer(quint16 genVer){
- this->_gen=genVer;
- this->versiontext->setHtml(this->version_body.arg(this->genVer()).arg(this->revVer()));
+ this->_gen=genVer;
+ this->versiontext->setHtml(this->version_body.arg(this->genVer()).arg(this->revVer()));
}
quint16 about::genVer(){return this->_gen;}
void about::setRevVer(quint16 revVer){
- this->_rev=revVer;
- this->versiontext->setHtml(this->version_body.arg(this->genVer()).arg(this->revVer()));
-}
-quint16 about::revVer(){
- return this->_rev;
+ this->_rev=revVer;
+ this->versiontext->setHtml(this->version_body.arg(this->genVer()).arg(this->revVer()));
}
+quint16 about::revVer(){return this->_rev;}
void about::setVersion(quint16 genVer, quint16 revVer){
- this->setGenVer(genVer);
- this->setRevVer(revVer);
+ this->setGenVer(genVer);
+ this->setRevVer(revVer);
}
#include "ui_about.h"
class about : virtual public QDialog,virtual private Ui::aboutDialogBase{
- Q_OBJECT
+ Q_OBJECT
public:
- about(QWidget *parent=NULL);
- quint16 genVer();
- quint16 revVer();
- void setGenVer(quint16 genVer);
- void setRevVer(quint16 revVer);
- void setVersion(quint16 genVer,quint16 revVer);
+ about(QWidget *parent=NULL);
+ quint16 genVer();
+ quint16 revVer();
+ void setGenVer(quint16 genVer);
+ void setRevVer(quint16 revVer);
+ void setVersion(quint16 genVer,quint16 revVer);
private:
- quint16 _gen, _rev;
- QString version_body;
+ quint16 _gen, _rev;
+ QString version_body;
};
#include "editdelegate.h"
-MemberListEditDelegate::MemberListEditDelegate(QObject *parent):
- QItemDelegate(parent){}
+MemberListEditDelegate::MemberListEditDelegate(QObject *parent):QItemDelegate(parent){}
QWidget *MemberListEditDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &option,const QModelIndex &index)const{
- QLineEdit *editor=qobject_cast<QLineEdit *>(QItemDelegate::createEditor(parent,option,index));
- editor->setValidator(new IPAddressValidator(false,editor));
- connect(editor,SIGNAL(editingFinished()),SLOT(edit_finished()));
- return editor;
+ QLineEdit *editor=qobject_cast<QLineEdit *>(QItemDelegate::createEditor(parent,option,index));
+ editor->setValidator(new IPAddressValidator(false,editor));
+ connect(editor,SIGNAL(editingFinished()),SLOT(edit_finished()));
+ return editor;
}
void MemberListEditDelegate::edit_finished(){
- QLineEdit *editor=qobject_cast<QLineEdit *>(this->sender());
- emit this->commitData(editor);
- emit this->closeEditor(editor);
+ QLineEdit *editor=qobject_cast<QLineEdit *>(this->sender());
+ emit this->commitData(editor);
+ emit this->closeEditor(editor);
}
#include"../validator/ipaddressvalidator.h"
class MemberListEditDelegate:virtual public QItemDelegate{
- Q_OBJECT
+ Q_OBJECT
public:
- MemberListEditDelegate(QObject *parent=NULL);
- QWidget *createEditor(QWidget *parent,const QStyleOptionViewItem &option,const QModelIndex &index)const;
+ MemberListEditDelegate(QObject *parent=NULL);
+ QWidget *createEditor(QWidget *parent,const QStyleOptionViewItem &option,const QModelIndex &index)const;
private slots:
- void edit_finished();
+ void edit_finished();
};
using namespace structures;
using namespace network;
mainWindow::mainWindow(){
- setupUi(this);
+ setupUi(this);
- this->settingdialog = new SettingDialog(this);
- this->memberList = new MemberList(this);
- this->sendTextEditor = new RtfEditor(this);
+ this->settingdialog = new SettingDialog(this);
+ this->memberList = new MemberList(this);
+ this->sendTextEditor = new RtfEditor(this);
- this->memberListPanel->addWidget(memberList);
- this->sendPanel->insertWidget(0,this->sendTextEditor,this->receivePanel->stretch(0));
+ this->memberListPanel->addWidget(memberList);
+ this->sendPanel->insertWidget(0,this->sendTextEditor,this->receivePanel->stretch(0));
- this->sendTextEditor->setFocus();
+ this->sendTextEditor->setFocus();
- QWidget::setTabOrder(this->sendTextEditor,this->sendButton);
- QWidget::setTabOrder(this->sendButton,this->sendFileButton);
- QWidget::setTabOrder(this->sendFileButton,this->addButton);
- QWidget::setTabOrder(this->addButton,this->removeButton);
- QWidget::setTabOrder(this->removeButton,this->editButton);
- QWidget::setTabOrder(this->editButton,this->receiveText);
+ QWidget::setTabOrder(this->sendTextEditor,this->sendButton);
+ QWidget::setTabOrder(this->sendButton,this->sendFileButton);
+ QWidget::setTabOrder(this->sendFileButton,this->addButton);
+ QWidget::setTabOrder(this->addButton,this->removeButton);
+ QWidget::setTabOrder(this->removeButton,this->editButton);
+ QWidget::setTabOrder(this->editButton,this->receiveText);
- //I'll reimpletemt the format of this memberlist file...
- connect(this->sendFileButton,SIGNAL(clicked()),SLOT(on_sendFileAction_triggered()));
- memberFilters<<tr("Jasmine memberlist file(%1)").arg("*.jsm")<<tr("All file(%1)").arg("*");
- logFilters<<tr("Text file(%1)").arg("*.txt")<<tr("All file(%1)").arg("*");
+ //I'll reimpletemt the format of this memberlist file...
+ connect(this->sendFileButton,SIGNAL(clicked()),SLOT(on_sendFileAction_triggered()));
+ memberFilters<<tr("Jasmine memberlist file(%1)").arg("*.jsm")<<tr("All file(%1)").arg("*");
+ logFilters<<tr("Text file(%1)").arg("*.txt")<<tr("All file(%1)").arg("*");
- /*//These behaviors are not implemented.
- this->sendButton->setEnabled(false);
- this->sendFileButton->setEnabled(false);
- this->sendFileAction->setEnabled(false);
- this->runServerAction->setEnabled(false);*/
+ /*//These behaviors are not implemented.
+ this->sendButton->setEnabled(false);
+ this->sendFileButton->setEnabled(false);
+ this->sendFileAction->setEnabled(false);
+ this->runServerAction->setEnabled(false);*/
- this->mainServer=new tcpServer(default_buffer_size,this);
+ this->mainServer=new tcpServer(default_buffer_size,this);
- connect(this->receiveText,SIGNAL(anchorClicked(const QUrl &)),SLOT(linkClicked(const QUrl &)));
- connect(this->receiveText,SIGNAL(highlighted(const QUrl &)),SLOT(selectedLink(const QUrl &)));
- connect(this->sendTextEditor,SIGNAL(invalidLink(const QString &)),SLOT(invalidLink(const QString &)));
- connect(this->sendTextEditor,SIGNAL(sendTriggered()),this->sendButton,SLOT(click()));
+ connect(this->receiveText,SIGNAL(anchorClicked(const QUrl &)),SLOT(linkClicked(const QUrl &)));
+ connect(this->receiveText,SIGNAL(highlighted(const QUrl &)),SLOT(selectedLink(const QUrl &)));
+ connect(this->sendTextEditor,SIGNAL(invalidLink(const QString &)),SLOT(invalidLink(const QString &)));
+ connect(this->sendTextEditor,SIGNAL(sendTriggered()),this->sendButton,SLOT(click()));
- connect(this->mainServer,SIGNAL(pending(const tcpSocket &)),SLOT(tcpserver_pending(const tcpSocket &)));
+ connect(this->mainServer,SIGNAL(pending(const tcpSocket &)),SLOT(tcpserver_pending(const tcpSocket &)));
}
mainWindow::~mainWindow(){}
void mainWindow::closeEvent(QCloseEvent *event){
- this->saveMember(default_memberlist);
- this->saveConfig(default_setting);
- event->accept();
+ this->saveMember(default_memberlist);
+ this->saveConfig(default_setting);
+ event->accept();
}
void mainWindow::showEvent(QShowEvent *event){
- if(rev==0)
- this->status->showMessage("<font color=\"#ff0000\">Don't forget almost all features are not implemented!</font>",default_status_interval);
- event->accept();
+ if(rev==0)
+ this->status->showMessage("<font color=\"#ff0000\">Don't forget almost all features are not implemented!</font>",default_status_interval);
+ event->accept();
}
//Client behavior
void mainWindow::on_sendButton_clicked(){
- QList<AddressAndPort> addressList=this->memberList->addressPortList();
+ QList<AddressAndPort> addressList=this->memberList->addressPortList();
#ifdef _OPENMP
#pragma omp parallel for
#endif
- for(int index=0;index<addressList.size();index++){
- tcpSocket *client=new tcpSocket(this->setting.name(),default_buffer_size,this);
- connect(client,SIGNAL(connected()),SLOT(tcpclient_connected()));
- connect(client,SIGNAL(error(const QAbstractSocket::SocketError &)),SLOT(tcpclient_error(const QAbstractSocket::SocketError &)));
- client->connectToHost(addressList[index].first,addressList[index].second);
- }
+ for(int index=0;index<addressList.size();index++){
+ tcpSocket *client=new tcpSocket(this->setting.name(),default_buffer_size,this);
+ connect(client,SIGNAL(connected()),SLOT(tcpclient_connected()));
+ connect(client,SIGNAL(error(const QAbstractSocket::SocketError &)),SLOT(tcpclient_error(const QAbstractSocket::SocketError &)));
+ connect(client,SIGNAL(sentData()),SLOT(sentData()));
+ client->connectToHost(addressList[index].first,addressList[index].second);
+ }
}
void mainWindow::tcpclient_error(const QAbstractSocket::SocketError &error){
- Q_UNUSED(error);
- tcpSocket *client=qobject_cast<tcpSocket *>(this->sender());
+ Q_UNUSED(error);
+ tcpSocket *client=qobject_cast<tcpSocket *>(this->sender());
#ifdef DEBUG
- qDebug()<<"Error:"<<client->errorString();
+ qDebug()<<"Error:"<<client->errorString();
#endif
- client->close();
+ client->close();
}
void mainWindow::tcpclient_connected(){
- tcpSocket *client=qobject_cast<tcpSocket *>(this->sender());
- (*client)<<this->sendTextEditor->html();
- client->disconnectFromHost();
- client->close();
+ tcpSocket *client=qobject_cast<tcpSocket *>(this->sender());
+ (*client)<<this->sendTextEditor->html();
+ client->disconnectFromHost();
+ client->close();
}
void mainWindow::on_sendFileAction_triggered(){
- //TODO:Send files
+ //TODO:Send files
+}
+void mainWindow::sentData(){
+ this->receiveText->append(setting.name()+"("+tr("me")+")"+tr(" says:"));
+ this->receiveText->append(this->sendTextEditor->html());
+ this->receiveText->append("<br />");
}
void mainWindow::on_runServerAction_triggered(bool checked){
- if(checked){
- if(this->mainServer->isListening()) this->mainServer->close();
- if(this->mainServer->listen(this->setting.bindingAddr(),this->setting.port())){
- this->status->showMessage(server_running.arg(this->mainServer->serverAddress().toString()).arg(this->mainServer->serverPort()),default_status_interval);
- this->serverSettingAction->setEnabled(false);
- }
- else this->mainServer->close();
- }else{
- if(!this->mainServer->isListening()) return;
- this->mainServer->close();
- this->status->showMessage(server_stopped,default_status_interval);
- this->serverSettingAction->setEnabled(true);
- }
+ if(checked){
+ if(this->mainServer->isListening()) this->mainServer->close();
+ if(this->mainServer->listen(this->setting.bindingAddr(),this->setting.port())){
+ this->status->showMessage(server_running.arg(this->mainServer->serverAddress().toString()).arg(this->mainServer->serverPort()),default_status_interval);
+ this->serverSettingAction->setEnabled(false);
+ }
+ else this->mainServer->close();
+ }else{
+ if(!this->mainServer->isListening()) return;
+ this->mainServer->close();
+ this->status->showMessage(server_stopped,default_status_interval);
+ this->serverSettingAction->setEnabled(true);
+ }
}
void mainWindow::settingDialog_accepted(){
- if(!this->mainServer->isListening()){
- if(!this->settingdialog->IPAddress().isNull())
- this->setting.setIPAddr(this->settingdialog->IPAddress());
- else
- QMessageBox::warning(this,invalid_IP_title,invalid_IP_body);
- this->setting.setPort(this->settingdialog->port());
- }
- this->setting.setName(this->settingdialog->nickName());
- this->setting.setNoloadMemberList(this->settingdialog->noloadMemberlist());
+ if(!this->mainServer->isListening()){
+ if(!this->settingdialog->IPAddress().isNull())
+ this->setting.setIPAddr(this->settingdialog->IPAddress());
+ else
+ QMessageBox::warning(this,invalid_IP_title,invalid_IP_body);
+ this->setting.setPort(this->settingdialog->port());
+ }
+ this->setting.setName(this->settingdialog->nickName());
+ this->setting.setNoloadMemberList(this->settingdialog->noloadMemberlist());
}
void mainWindow::configAndShowSettingDialog(const SettingDialog::tab tab){
- this->settingdialog->setTabEnabled(SettingDialog::server,!this->mainServer->isListening());
- this->settingdialog->setAddressAndPort(AddressAndPort(this->setting.bindingAddr(),this->setting.port()));
- this->settingdialog->setNickName(this->setting.name());
- this->settingdialog->setNoloadMemberlist(this->setting.noloadMemberList());
- this->settingdialog->setTab(tab);
- connect(settingdialog,SIGNAL(accepted()),SLOT(settingDialog_accepted()));
- settingdialog->exec();
+ this->settingdialog->setTabEnabled(SettingDialog::server,!this->mainServer->isListening());
+ this->settingdialog->setAddressAndPort(AddressAndPort(this->setting.bindingAddr(),this->setting.port()));
+ this->settingdialog->setNickName(this->setting.name());
+ this->settingdialog->setNoloadMemberlist(this->setting.noloadMemberList());
+ this->settingdialog->setTab(tab);
+ connect(settingdialog,SIGNAL(accepted()),SLOT(settingDialog_accepted()));
+ settingdialog->exec();
}
void mainWindow::on_serverSettingAction_triggered(){configAndShowSettingDialog(SettingDialog::server);}
void mainWindow::on_clientSettingAction_triggered(){configAndShowSettingDialog(SettingDialog::client);}
void mainWindow::on_miscAction_triggered(){configAndShowSettingDialog(SettingDialog::misc);}
void mainWindow::on_saveConfigAction_triggered(){
- QFileDialog dialog(this,Qt::Dialog);
- dialog.setWindowTitle(save_setting_title);
- dialog.setNameFilter("Jasmine setting file (*.jst)");
- dialog.setAcceptMode(QFileDialog::AcceptSave);
+ QFileDialog dialog(this,Qt::Dialog);
+ dialog.setWindowTitle(save_setting_title);
+ dialog.setNameFilter("Jasmine setting file (*.jst)");
+ dialog.setAcceptMode(QFileDialog::AcceptSave);
- connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveConfig(const QString &)));
- dialog.exec();
+ connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveConfig(const QString &)));
+ dialog.exec();
}
void mainWindow::on_openConfigAction_triggered(){
- QFileDialog dialog(this,Qt::Dialog);
- dialog.setWindowTitle(open_setting_title);
- dialog.setNameFilter("Jasmine setting file (*.jst)");
- dialog.setAcceptMode(QFileDialog::AcceptOpen);
+ QFileDialog dialog(this,Qt::Dialog);
+ dialog.setWindowTitle(open_setting_title);
+ dialog.setNameFilter("Jasmine setting file (*.jst)");
+ dialog.setAcceptMode(QFileDialog::AcceptOpen);
- connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(openConfig(const QString &)));
- dialog.exec();
+ connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(openConfig(const QString &)));
+ dialog.exec();
}
void mainWindow::on_openMemberListAction_triggered(){
- QFileDialog *dialog=new QFileDialog(this,open_memberlist_title,"",this->memberFilters.join(";;"));
- dialog->setAcceptMode(QFileDialog::AcceptOpen);
- connect(dialog,SIGNAL(fileSelected(const QString &)),SLOT(openMember(const QString &)));
- dialog->exec();
- delete dialog;
+ QFileDialog *dialog=new QFileDialog(this,open_memberlist_title,"",this->memberFilters.join(";;"));
+ dialog->setAcceptMode(QFileDialog::AcceptOpen);
+ connect(dialog,SIGNAL(fileSelected(const QString &)),SLOT(openMember(const QString &)));
+ dialog->exec();
+ delete dialog;
}
void mainWindow::on_saveMemberListAction_triggered(){
- QFileDialog dialog(this,Qt::Dialog);
- dialog.setWindowTitle(save_memberlist_title);
- dialog.setNameFilters(this->memberFilters);
- dialog.setAcceptMode(QFileDialog::AcceptSave);
+ QFileDialog dialog(this,Qt::Dialog);
+ dialog.setWindowTitle(save_memberlist_title);
+ dialog.setNameFilters(this->memberFilters);
+ dialog.setAcceptMode(QFileDialog::AcceptSave);
- connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveMember(const QString &)));
- dialog.exec();
+ connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveMember(const QString &)));
+ dialog.exec();
}
void mainWindow::on_saveLogAction_triggered(){
- QFileDialog dialog(this,Qt::Dialog);
- dialog.setWindowTitle(save_log_title);
- dialog.setNameFilters(this->logFilters);
- dialog.setAcceptMode(QFileDialog::AcceptSave);
+ QFileDialog dialog(this,Qt::Dialog);
+ dialog.setWindowTitle(save_log_title);
+ dialog.setNameFilters(this->logFilters);
+ dialog.setAcceptMode(QFileDialog::AcceptSave);
- connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveLog(const QString &)));
- dialog.exec();
+ connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveLog(const QString &)));
+ dialog.exec();
}
void mainWindow::on_aboutAction_triggered(){
- about aboutDialog(this);
- aboutDialog.exec();
+ about aboutDialog(this);
+ aboutDialog.exec();
}
void mainWindow::on_actionExit_triggered(){qApp->exit(0);}
void mainWindow::on_clearAction_triggered(){this->receiveText->clear();}
void mainWindow::on_addButton_clicked(){
- QTableWidgetItem *name=new QTableWidgetItem(),*address=new QTableWidgetItem();
- this->memberList->insertRow(this->memberList->rowCount());
- name->setText(edithere);
- address->setText(edithere);
- this->memberList->setItem(this->memberList->rowCount()-1,0,name);
- this->memberList->setItem(this->memberList->rowCount()-1,1,address);
- this->memberList->setCurrentItem(name);
- this->memberList->editItem(name);
+ QTableWidgetItem *name=new QTableWidgetItem(),*address=new QTableWidgetItem();
+ this->memberList->insertRow(this->memberList->rowCount());
+ name->setText(edithere);
+ address->setText(edithere);
+ this->memberList->setItem(this->memberList->rowCount()-1,0,name);
+ this->memberList->setItem(this->memberList->rowCount()-1,1,address);
+ this->memberList->setCurrentItem(name);
+ this->memberList->editItem(name);
}
void mainWindow::on_removeButton_clicked(){this->memberList->remove_selected();}
void mainWindow::saveConfig(const QString &file){
- QFile filestream(file);
- if(!filestream.open(QFile::WriteOnly)){
- QMessageBox::critical(this,write_error_title,write_error_body.arg(filestream.fileName()).arg(filestream.errorString()));
- return;
- }
- QDataStream datastream(&filestream);
- datastream<<setting;
- filestream.close();
+ QFile filestream(file);
+ if(!filestream.open(QFile::WriteOnly)){
+ QMessageBox::critical(this,write_error_title,write_error_body.arg(filestream.fileName()).arg(filestream.errorString()));
+ return;
+ }
+ QDataStream datastream(&filestream);
+ datastream<<setting;
+ filestream.close();
}
void mainWindow::saveMember(const QString &file){
- QFile filestream(file);
- if(!filestream.open(QFile::WriteOnly)){
- QMessageBox::critical(this,write_error_title,
- write_error_body.arg(file).arg(filestream.errorString()));
- return;
- }
- QDataStream datastream(&filestream);
- datastream.setVersion(QDataStream::Qt_4_6);
- datastream<<(*this->memberList);
- filestream.close();
+ QFile filestream(file);
+ if(!filestream.open(QFile::WriteOnly)){
+ QMessageBox::critical(this,write_error_title,
+ write_error_body.arg(file).arg(filestream.errorString()));
+ return;
+ }
+ QDataStream datastream(&filestream);
+ datastream.setVersion(QDataStream::Qt_4_6);
+ datastream<<(*this->memberList);
+ filestream.close();
}
void mainWindow::saveLog(const QString &file){
- QFile filestream(file);
- if(!filestream.open(QFile::WriteOnly)){
- QMessageBox::critical(this,write_error_title,write_error_body.arg(file).arg(filestream.errorString()));
- return;
- }
- filestream.write(this->receiveText->toPlainText().toUtf8());
- filestream.close();
+ QFile filestream(file);
+ if(!filestream.open(QFile::WriteOnly)){
+ QMessageBox::critical(this,write_error_title,write_error_body.arg(file).arg(filestream.errorString()));
+ return;
+ }
+ filestream.write(this->receiveText->toPlainText().toUtf8());
+ filestream.close();
}
void mainWindow::openConfig(const QString &file){
- QFile filestream(file);
- if(!filestream.exists()){
- QMessageBox::critical(this, file_not_found_dialog_title,file_not_found_dialog_body.arg(filestream.fileName()));
- return;
- }
- if(!filestream.open(QFile::ReadOnly)){
- QMessageBox::critical(this,read_error_title,read_error_body.arg(filestream.fileName()).arg(filestream.errorString()));
- return;
- }
- QDataStream datastream(&filestream);
- datastream>>setting;
- filestream.close();
- QMessageBox::information(this,loadingSettingSucceeded_title,loadingSettingSucceeded_body.arg(filestream.fileName()));
+ QFile filestream(file);
+ if(!filestream.exists()){
+ QMessageBox::critical(this, file_not_found_dialog_title,file_not_found_dialog_body.arg(filestream.fileName()));
+ return;
+ }
+ if(!filestream.open(QFile::ReadOnly)){
+ QMessageBox::critical(this,read_error_title,read_error_body.arg(filestream.fileName()).arg(filestream.errorString()));
+ return;
+ }
+ QDataStream datastream(&filestream);
+ datastream>>setting;
+ filestream.close();
+ QMessageBox::information(this,loadingSettingSucceeded_title,loadingSettingSucceeded_body.arg(filestream.fileName()));
}
void mainWindow::openMember(const QString &file){
- /*
- Does QFileDialog have a bug??
- If you select file by double clicking, fileSelected signal will be emitted twice.
- */
- if(this->sender()!=NULL&&this->sender()==this->beforesender) return;
- this->beforesender=this->sender();
- if(this->memberList->rowCount()>0&&
- QMessageBox::warning(this,overwrite_memberlist_body,overwrite_memberlist_body
- ,QMessageBox::Yes|QMessageBox::No)==QMessageBox::No)return;
- QFile filestream(file);
- if(!filestream.exists()){
- QMessageBox::critical(this,file_not_found_dialog_title,file_not_found_dialog_body.arg(filestream.fileName()));
- return;
- }
- if(!filestream.open(QFile::ReadOnly)){
- QMessageBox::critical(this,read_error_title,read_error_body.arg(filestream.fileName()).arg(filestream.errorString()));
- return;
- }
- QDataStream datastream(&filestream);
- datastream.setVersion(QDataStream::Qt_4_6);
- datastream>>(*this->memberList);
- filestream.close();
+ /*
+ Does QFileDialog have a bug??
+ If you select file by double clicking, fileSelected signal will be emitted twice.
+ */
+ if(this->sender()!=NULL&&this->sender()==this->beforesender) return;
+ this->beforesender=this->sender();
+ if(this->memberList->rowCount()>0&&
+ QMessageBox::warning(this,overwrite_memberlist_body,overwrite_memberlist_body
+ ,QMessageBox::Yes|QMessageBox::No)==QMessageBox::No)return;
+ QFile filestream(file);
+ if(!filestream.exists()){
+ QMessageBox::critical(this,file_not_found_dialog_title,file_not_found_dialog_body.arg(filestream.fileName()));
+ return;
+ }
+ if(!filestream.open(QFile::ReadOnly)){
+ QMessageBox::critical(this,read_error_title,read_error_body.arg(filestream.fileName()).arg(filestream.errorString()));
+ return;
+ }
+ QDataStream datastream(&filestream);
+ datastream.setVersion(QDataStream::Qt_4_6);
+ datastream>>(*this->memberList);
+ filestream.close();
}
void mainWindow::linkClicked(const QUrl &link){if(!link.scheme().isEmpty()) QDesktopServices::openUrl(link);}
void mainWindow::invalidLink(const QString &link){this->status->showMessage(invalid_link.arg(link),default_status_interval);}
void mainWindow::selectedLink(const QUrl &link){
- if(link.scheme().isEmpty()||!link.isValid()){
- this->status->clearMessage();
- return;
- }
- this->status->showMessage(link.toString(QUrl::None));
+ if(link.scheme().isEmpty()||!link.isValid()){
+ this->status->clearMessage();
+ return;
+ }
+ this->status->showMessage(link.toString(QUrl::None));
}
settings mainWindow::app_setting() const{return this->setting;}
//Implementations for main server.
bool mainWindow::tcpserver_pending(const tcpSocket &socket){
#ifdef DEBUG
- qDebug()<<"Pending:"<<socket.peerAddress().toString()<<" Port:"<<socket.peerPort();
+ qDebug()<<"Pending:"<<socket.peerAddress().toString()<<" Port:"<<socket.peerPort();
#endif
- if(this->memberList->isInMember(AddressAndPort(socket.peerAddress(),0),true)<0) return false;
- connect(&socket,
- SIGNAL(msg_received(const QString &)),
- SLOT(tcpserver_msg_received(const QString &)));
- connect(&socket,SIGNAL(error(const QAbstractSocket::SocketError &)),
- SLOT(tcpserver_error(const QAbstractSocket::SocketError &)));
- return true;
+ if(this->memberList->isInMember(AddressAndPort(socket.peerAddress(),0),true)<0) return false;
+ connect(&socket,
+ SIGNAL(msg_received(const QString &)),
+ SLOT(tcpserver_msg_received(const QString &)));
+ connect(&socket,SIGNAL(error(const QAbstractSocket::SocketError &)),
+ SLOT(tcpserver_error(const QAbstractSocket::SocketError &)));
+ return true;
}
void mainWindow::tcpserver_error(const QAbstractSocket::SocketError &error){
- Q_UNUSED(error);
- tcpSocket *sender=qobject_cast<tcpSocket *>(this->sender());
+ Q_UNUSED(error);
+ tcpSocket *sender=qobject_cast<tcpSocket *>(this->sender());
#ifdef DEBUG
- qDebug()<<"Receive aborted:"<<sender->errorString();
+ qDebug()<<"Receive aborted:"<<sender->errorString();
#endif
- sender->close();
+ sender->close();
}
void mainWindow::tcpserver_msg_received(const QString &msg){
- tcpSocket *sender=qobject_cast<tcpSocket *>(this->sender());
- this->receiveText->append(sender->header_data().senderName()+"("+this->memberList->name(AddressAndPort(sender->peerAddress(),0),true)+", "+sender->peerAddress().toString()+")"+tr(" says:"));
- this->receiveText->append(msg);
- this->receiveText->append("<br />");
+ tcpSocket *sender=qobject_cast<tcpSocket *>(this->sender());
+ this->receiveText->append(sender->header_data().senderName()+"("+this->memberList->name(AddressAndPort(sender->peerAddress(),0),true)+", "+sender->peerAddress().toString()+")"+tr(" says:"));
+ this->receiveText->append(msg);
+ this->receiveText->append("<br />");
}
using namespace network;
class mainWindow:public QMainWindow,private Ui::MainWindow{
- Q_OBJECT
+ Q_OBJECT
public:
- mainWindow();
- ~mainWindow();
+ mainWindow();
+ ~mainWindow();
private slots:
- //These functions work automatically by automatic connection.
- void on_sendButton_clicked();
- void on_runServerAction_triggered(bool);
- void on_serverSettingAction_triggered();
- void on_clientSettingAction_triggered();
- void on_miscAction_triggered();
- void on_sendFileAction_triggered();
- void on_aboutAction_triggered();
- void on_openMemberListAction_triggered();
- void on_saveLogAction_triggered();
- void on_saveMemberListAction_triggered();
- void on_actionExit_triggered();
- void on_clearAction_triggered();
- void on_addButton_clicked();
- void on_removeButton_clicked();
- void on_saveConfigAction_triggered();
- void on_openConfigAction_triggered();
- //This function works manually.
- void settingDialog_accepted();
- //These are for saving stuff.
- void saveConfig(const QString &);
- void saveMember(const QString &);
- void saveLog(const QString &);
- //This is for links.
- void linkClicked(const QUrl &);
- //These slots are for receiveText.
- void invalidLink(const QString &);
- void selectedLink(const QUrl &);
- //These functions are for tcpclient.
- void tcpclient_connected();
- void tcpclient_error(const QAbstractSocket::SocketError &error);
- //These functions are for tcpserver.
- bool tcpserver_pending(const tcpSocket &);
- void tcpserver_msg_received(const QString &);
- void tcpserver_error(const QAbstractSocket::SocketError &);
+ //These functions work automatically by automatic connection.
+ void on_sendButton_clicked();
+ void on_runServerAction_triggered(bool);
+ void on_serverSettingAction_triggered();
+ void on_clientSettingAction_triggered();
+ void on_miscAction_triggered();
+ void on_sendFileAction_triggered();
+ void on_aboutAction_triggered();
+ void on_openMemberListAction_triggered();
+ void on_saveLogAction_triggered();
+ void on_saveMemberListAction_triggered();
+ void on_actionExit_triggered();
+ void on_clearAction_triggered();
+ void on_addButton_clicked();
+ void on_removeButton_clicked();
+ void on_saveConfigAction_triggered();
+ void on_openConfigAction_triggered();
+ //This function works manually.
+ void settingDialog_accepted();
+ //These are for saving stuff.
+ void saveConfig(const QString &);
+ void saveMember(const QString &);
+ void saveLog(const QString &);
+ //This is for links.
+ void linkClicked(const QUrl &);
+ //These slots are for receiveText.
+ void invalidLink(const QString &);
+ void selectedLink(const QUrl &);
+ //These functions are for tcpclient.
+ void tcpclient_connected();
+ void tcpclient_error(const QAbstractSocket::SocketError &error);
+ void sentData();
+ //These functions are for tcpserver.
+ bool tcpserver_pending(const tcpSocket &);
+ void tcpserver_msg_received(const QString &);
+ void tcpserver_error(const QAbstractSocket::SocketError &);
public slots:
- //These are for opening stuff.
- void openConfig(const QString &);
- void openMember(const QString &);
+ //These are for opening stuff.
+ void openConfig(const QString &);
+ void openMember(const QString &);
protected:
- //Events
- void closeEvent(QCloseEvent *);
- void showEvent(QShowEvent *);
+ //Events
+ void closeEvent(QCloseEvent *);
+ void showEvent(QShowEvent *);
private:
- QObject *beforesender;
- QStringList memberFilters,logFilters;
+ QObject *beforesender;
+ QStringList memberFilters,logFilters;
- MemberList *memberList;
- RtfEditor *sendTextEditor;
- tcpServer *mainServer;
- SettingDialog *settingdialog;
- settings setting;
+ MemberList *memberList;
+ RtfEditor *sendTextEditor;
+ tcpServer *mainServer;
+ SettingDialog *settingdialog;
+ settings setting;
- bool isInMember(const AddressAndPort &,bool matchIPOnly);
- void configAndShowSettingDialog(const SettingDialog::tab);
+ bool isInMember(const AddressAndPort &,bool matchIPOnly);
+ void configAndShowSettingDialog(const SettingDialog::tab);
public:
- settings app_setting() const;
+ settings app_setting() const;
};
#include <QString>
#include <QObject>
QString save_prefix(QObject::tr("Save %1")),
- open_prefix(QObject::tr("Open %1")),
+ open_prefix(QObject::tr("Open %1")),
- save_as_title(save_prefix.arg(QObject::tr("as"))),
- save_setting_title(save_prefix.arg(QObject::tr("settings"))),
- save_memberlist_title(save_prefix.arg(QObject::tr("memberlist"))),
- save_log_title(save_prefix.arg(QObject::tr("log"))),
+ save_as_title(save_prefix.arg(QObject::tr("as"))),
+ save_setting_title(save_prefix.arg(QObject::tr("settings"))),
+ save_memberlist_title(save_prefix.arg(QObject::tr("memberlist"))),
+ save_log_title(save_prefix.arg(QObject::tr("log"))),
- close_warning_title(QObject::tr("Data will be lost!")),
- saving_member_warning_when_closing_body(QObject::tr("The modification of your memberlist will be lost without saving it. Save it?")),
- saving_setting_warning_when_closing_body(QObject::tr("The modification of your memberlist will be lost witout saving it. Save it?")),
+ close_warning_title(QObject::tr("Data will be lost!")),
+ saving_member_warning_when_closing_body(QObject::tr("The modification of your memberlist will be lost without saving it. Save it?")),
+ saving_setting_warning_when_closing_body(QObject::tr("The modification of your memberlist will be lost witout saving it. Save it?")),
- open_memberlist_title(open_prefix.arg(QObject::tr("memberlist"))),
- open_setting_title(open_prefix.arg(QObject::tr("settings"))),
+ open_memberlist_title(open_prefix.arg(QObject::tr("memberlist"))),
+ open_setting_title(open_prefix.arg(QObject::tr("settings"))),
- overwrite_memberlist_title(QObject::tr("Overwrite?")),
- overwrite_memberlist_body(QObject::tr("There are some members in your current list. If loding file, the current memberlist will be lost. \n"
- "Load the file?")),
- invalid_IP_title(QObject::tr("Invalid IPAddress.")),
- invalid_IP_body(QObject::tr("The specified IPAddress is invalid. Writing it down on the setting is ignored.")),
+ overwrite_memberlist_title(QObject::tr("Overwrite?")),
+ overwrite_memberlist_body(QObject::tr("There are some members in your current list. If loding file, the current memberlist will be lost. \n"
+ "Load the file?")),
+ invalid_IP_title(QObject::tr("Invalid IPAddress.")),
+ invalid_IP_body(QObject::tr("The specified IPAddress is invalid. Writing it down on the setting is ignored.")),
- file_not_found_dialog_title(QObject::tr("Where is the file?")),
- file_not_found_dialog_body(QObject::tr("Couldn't find the specified file:%1")),
+ file_not_found_dialog_title(QObject::tr("Where is the file?")),
+ file_not_found_dialog_body(QObject::tr("Couldn't find the specified file:%1")),
- read_error_title(QObject::tr("Couldn't read")),
- read_error_body(QObject::tr("Couldn't read %1 because of the following reason.\n%2")),
+ read_error_title(QObject::tr("Couldn't read")),
+ read_error_body(QObject::tr("Couldn't read %1 because of the following reason.\n%2")),
- write_error_title(QObject::tr("Couldn't write")),
- write_error_body(QObject::tr("Couldn't open the stream for %1. The reason is following:\n%2")),
+ write_error_title(QObject::tr("Couldn't write")),
+ write_error_body(QObject::tr("Couldn't open the stream for %1. The reason is following:\n%2")),
- edithere(QObject::tr("Edit here")),
- settingFilter("Jasmine setting file(*.jst)"),
+ edithere(QObject::tr("Edit here")),
+ settingFilter("Jasmine setting file(*.jst)"),
- loadingSettingSucceeded_title(QObject::tr("Loading succeeded")),
- loadingSettingSucceeded_body(QObject::tr("Loading settings: %1 has been succeeded.")),
+ loadingSettingSucceeded_title(QObject::tr("Loading succeeded")),
+ loadingSettingSucceeded_body(QObject::tr("Loading settings: %1 has been succeeded.")),
- invalid_link(QObject::tr("Input link is not valid: %1")),
- server_running(QObject::tr("Server is running now. (%1:%2)")),
- server_stopped(QObject::tr("Server has been stopped."));
+ invalid_link(QObject::tr("Input link is not valid: %1")),
+ server_running(QObject::tr("Server is running now. (%1:%2)")),
+ server_stopped(QObject::tr("Server has been stopped."));
#define NameIndex 0
MemberList::MemberList(QWidget *parent):QTableWidget(parent){
- this->verticalHeader()->setVisible(false);
- this->verticalHeader()->setDefaultSectionSize(15);
- this->verticalHeader()->setDefaultSectionSize(15);
- this->setColumnCount(2);
- QStringList labels;
- labels<<tr("Name")<<tr("IPAddress");
- this->setHorizontalHeaderLabels(labels);
- this->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
- this->horizontalHeader()->setVisible(true);
- this->setItemDelegateForColumn(1,new MemberListEditDelegate(this));
+ this->verticalHeader()->setVisible(false);
+ this->verticalHeader()->setDefaultSectionSize(15);
+ this->verticalHeader()->setDefaultSectionSize(15);
+ this->setColumnCount(2);
+ QStringList labels;
+ labels<<tr("Name")<<tr("IPAddress");
+ this->setHorizontalHeaderLabels(labels);
+ this->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+ this->horizontalHeader()->setVisible(true);
+ this->setItemDelegateForColumn(1,new MemberListEditDelegate(this));
}
QList<AddressAndPort> MemberList::addressPortList() const{
- QList<AddressAndPort> ret;
- for(int row=0;row<this->rowCount();row++){
- QStringList address_port_str=this->item(row,AddressIndex)->text().split(":");
- if(address_port_str.size()<2) address_port_str<<QString("%1").arg(default_port);
- if(address_port_str[1].isEmpty()) address_port_str[1]=QString("%1").arg(default_port);
- AddressAndPort address_port(QHostAddress(address_port_str[0]),address_port_str[1].toUShort());
- ret<<address_port;
- }
- return ret;
+ QList<AddressAndPort> ret;
+ for(int row=0;row<this->rowCount();row++){
+ QStringList address_port_str=this->item(row,AddressIndex)->text().split(":");
+ if(address_port_str.size()<2) address_port_str<<QString("%1").arg(default_port);
+ if(address_port_str[1].isEmpty()) address_port_str[1]=QString("%1").arg(default_port);
+ AddressAndPort address_port(QHostAddress(address_port_str[0]),address_port_str[1].toUShort());
+ ret<<address_port;
+ }
+ return ret;
}
int MemberList::isInMember(const AddressAndPort &peer,bool matchIPOnly)const{
- for(int row=0;row<this->rowCount();row++){
- QStringList address_port_str=this->item(row,AddressIndex)->text().split(":");
- if(address_port_str.size()<2) address_port_str<<QString("%1").arg(default_port);
- if(address_port_str[1].isEmpty()) address_port_str[1]=QString("%1").arg(default_port);
- if(matchIPOnly&&address_port_str[0]==peer.first.toString()) return row;
- else if(address_port_str[0]==peer.first.toString()&&
- address_port_str[1]==QString::number(peer.second))
- return row;
- }
- return -1;
+ for(int row=0;row<this->rowCount();row++){
+ QStringList address_port_str=this->item(row,AddressIndex)->text().split(":");
+ if(address_port_str.size()<2) address_port_str<<QString("%1").arg(default_port);
+ if(address_port_str[1].isEmpty()) address_port_str[1]=QString("%1").arg(default_port);
+ if(matchIPOnly&&address_port_str[0]==peer.first.toString()) return row;
+ else if(address_port_str[0]==peer.first.toString()&&
+ address_port_str[1]==QString::number(peer.second))
+ return row;
+ }
+ return -1;
}
QString MemberList::name(const AddressAndPort &addressport, bool matchAddressOnly) const{
- int index=this->isInMember(addressport,matchAddressOnly);
- return this->item(index,NameIndex)->text();
+ int index=this->isInMember(addressport,matchAddressOnly);
+ return this->item(index,NameIndex)->text();
}
void MemberList::remove_selected(){
- while(this->selectedItems().size()>0&&this->selectedRanges()[0].rowCount()>0)
- this->removeRow(this->selectedRanges()[0].topRow());
+ while(this->selectedItems().size()>0&&this->selectedRanges()[0].rowCount()>0)
+ this->removeRow(this->selectedRanges()[0].topRow());
}
void MemberList::remove_all_contents(){while(this->rowCount()>0) this->removeRow(0);}
void MemberList::keyReleaseEvent(QKeyEvent *event){
- if(event->matches(QKeySequence::Delete)){
- remove_selected();
- event->ignore();
- }else event->accept();
+ if(event->matches(QKeySequence::Delete)){
+ remove_selected();
+ event->ignore();
+ }else event->accept();
}
#define AddressIndex 1
#define NameIndex 0
class MemberList:virtual public QTableWidget{
- Q_OBJECT
+ Q_OBJECT
public:
- MemberList(QWidget *parent=NULL);
+ MemberList(QWidget *parent=NULL);
public slots:
- void remove_selected();
- void remove_all_contents();
- QList<AddressAndPort> addressPortList() const;
- QString name(const AddressAndPort&,bool) const;
- int isInMember(const AddressAndPort &peer,bool matchIPOnly)const;
- friend QDataStream &operator<<(QDataStream &out,const MemberList &value){
- QList<NameAndAddrPort> AddressList;
- for(int row=0;row<value.rowCount();row++){
- QStringList AddrAndPort=value.item(row,AddressIndex)->text().split(":");
- AddressList<<NameAndAddrPort(value.item(row,NameIndex)->text(),AddressAndPort(QHostAddress(AddrAndPort[0]),(AddrAndPort.count()==2)? AddrAndPort[1].toUShort():default_port));
- }
- out<<AddressList;
- return out;
- }
+ void remove_selected();
+ void remove_all_contents();
+ QList<AddressAndPort> addressPortList() const;
+ QString name(const AddressAndPort&,bool) const;
+ int isInMember(const AddressAndPort &peer,bool matchIPOnly)const;
+ friend QDataStream &operator<<(QDataStream &out,const MemberList &value){
+ QList<NameAndAddrPort> AddressList;
+ for(int row=0;row<value.rowCount();row++){
+ QStringList AddrAndPort=value.item(row,AddressIndex)->text().split(":");
+ AddressList<<NameAndAddrPort(value.item(row,NameIndex)->text(),AddressAndPort(QHostAddress(AddrAndPort[0]),(AddrAndPort.count()==2)? AddrAndPort[1].toUShort():default_port));
+ }
+ out<<AddressList;
+ return out;
+ }
- friend QDataStream &operator>>(QDataStream &in, MemberList &value){
- QList<NameAndAddrPort> AddressList;
- in>>AddressList;
- value.remove_all_contents();
- foreach(NameAndAddrPort addressList,AddressList){
- QTableWidgetItem *name=new QTableWidgetItem(addressList.first),
- *AddressPort=new QTableWidgetItem(QString("%1:%2").
- arg(addressList.second.first.toString()).
- arg(addressList.second.second));
- value.insertRow(value.rowCount());
- value.setItem(value.rowCount()-1,NameIndex,name);
- value.setItem(value.rowCount()-1,AddressIndex,AddressPort);
- }
- return in;
- }
+ friend QDataStream &operator>>(QDataStream &in, MemberList &value){
+ QList<NameAndAddrPort> AddressList;
+ in>>AddressList;
+ value.remove_all_contents();
+ foreach(NameAndAddrPort addressList,AddressList){
+ QTableWidgetItem *name=new QTableWidgetItem(addressList.first),
+ *AddressPort=new QTableWidgetItem(QString("%1:%2").
+ arg(addressList.second.first.toString()).
+ arg(addressList.second.second));
+ value.insertRow(value.rowCount());
+ value.setItem(value.rowCount()-1,NameIndex,name);
+ value.setItem(value.rowCount()-1,AddressIndex,AddressPort);
+ }
+ return in;
+ }
private:
- void keyReleaseEvent(QKeyEvent *);
+ void keyReleaseEvent(QKeyEvent *);
};
#include "rtfeditor.h"
RtfEditor::RtfEditor(QWidget *parent):QWidget(parent){
- this->toolbar =new QToolBar(this);
- this->editor =new QTextEdit(this);
- this->layout =new QVBoxLayout(this);
- this->layout->addWidget(this->toolbar);
- this->layout->addWidget(this->editor);
+ this->toolbar =new QToolBar(this);
+ this->editor =new QTextEdit(this);
+ this->layout =new QVBoxLayout(this);
+ this->layout->addWidget(this->toolbar);
+ this->layout->addWidget(this->editor);
- this->defaltTextColor=this->editor->textColor();
- this->bold =this->toolbar->addAction(QIcon(":/rtfeditor/bold"),"Bold");
- this->italic=this->toolbar->addAction(QIcon(":/rtfeditor/italic"),"Italic");
- this->color =this->toolbar->addAction(QIcon(":/rtfeditor/color"),"Color");
- this->link =this->toolbar->addAction(QIcon(":/rtfeditor/link"),"Link");
+ this->defaltTextColor=this->editor->textColor();
+ this->bold =this->toolbar->addAction(QIcon(":/rtfeditor/bold"),"Bold");
+ this->italic=this->toolbar->addAction(QIcon(":/rtfeditor/italic"),"Italic");
+ this->color =this->toolbar->addAction(QIcon(":/rtfeditor/color"),"Color");
+ this->link =this->toolbar->addAction(QIcon(":/rtfeditor/link"),"Link");
- connect(this->bold, SIGNAL(triggered(bool)), SLOT(makeBold(bool)));
- connect(this->italic, SIGNAL(triggered(bool)), SLOT(makeItalic(bool)));
- connect(this->link, SIGNAL(triggered(bool)), SLOT(makeLink(bool)));
- connect(this->color, SIGNAL(triggered(bool)), SLOT(makeColor(bool)));
- connect(this->editor, SIGNAL(cursorPositionChanged()), SLOT(selectionChnged()));
+ connect(this->bold, SIGNAL(triggered(bool)), SLOT(makeBold(bool)));
+ connect(this->italic, SIGNAL(triggered(bool)), SLOT(makeItalic(bool)));
+ connect(this->link, SIGNAL(triggered(bool)), SLOT(makeLink(bool)));
+ connect(this->color, SIGNAL(triggered(bool)), SLOT(makeColor(bool)));
+ connect(this->editor, SIGNAL(cursorPositionChanged()), SLOT(selectionChnged()));
- this->bold->setCheckable(true);
- this->italic->setCheckable(true);
- this->link->setCheckable(true);
- this->color->setCheckable(true);
+ this->bold->setCheckable(true);
+ this->italic->setCheckable(true);
+ this->link->setCheckable(true);
+ this->color->setCheckable(true);
#ifdef DEBUG
- qDebug()<<"Rtf editor has initialized. When you press any key(s), keysym will be output to stdout.";
+ qDebug()<<"Rtf editor has initialized. When you press any key(s), keysym will be output to stdout.";
#endif
}
void RtfEditor::selectionChnged(){
- this->bold->setChecked(this->editor->currentFont().bold());
- this->italic->setChecked(this->editor->currentFont().italic());
- this->link->setChecked(this->editor->currentCharFormat().isAnchor());
- if(!this->editor->currentCharFormat().isAnchor())
- this->color->setChecked(this->editor->textColor()!=this->defaltTextColor);
- else
- this->color->setChecked(this->editor->currentCharFormat().foreground().color()!=this->colorset.color(QPalette::Link));
+ this->bold->setChecked(this->editor->currentFont().bold());
+ this->italic->setChecked(this->editor->currentFont().italic());
+ this->link->setChecked(this->editor->currentCharFormat().isAnchor());
+ if(!this->editor->currentCharFormat().isAnchor())
+ this->color->setChecked(this->editor->textColor()!=this->defaltTextColor);
+ else
+ this->color->setChecked(this->editor->currentCharFormat().foreground().color()!=this->colorset.color(QPalette::Link));
}
void RtfEditor::makeStyle(const style s,bool on){
- QFont font=this->editor->currentFont();
- switch(s){
- case RtfEditor::Bold:
- font.setBold(on);
- break;
- case RtfEditor::Italic:
- font.setItalic(on);
- break;
- default:return;
- }
- this->editor->setCurrentFont(font);
+ QFont font=this->editor->currentFont();
+ switch(s){
+ case RtfEditor::Bold:
+ font.setBold(on);
+ break;
+ case RtfEditor::Italic:
+ font.setItalic(on);
+ break;
+ default:return;
+ }
+ this->editor->setCurrentFont(font);
}
void RtfEditor::makeBold(bool checked){this->makeStyle(RtfEditor::Bold,checked);}
void RtfEditor::makeItalic(bool checked){this->makeStyle(RtfEditor::Italic,checked);}
void RtfEditor::makeColor(bool checked){
- if(checked){
- QColorDialog dialog(this);
- connect(&dialog,SIGNAL(colorSelected(const QColor &)),this->editor,SLOT(setTextColor(const QColor &)));
- connect(&dialog,SIGNAL(rejected()),SLOT(selectionChnged()));
- dialog.exec();
- if(this->editor->currentCharFormat().isAnchor()) this->selectionChnged();
- }else{
- QTextCharFormat format=this->editor->currentCharFormat();
- if(format.isAnchor())
- format.setForeground(QBrush(this->colorset.color(QPalette::Link)));
- else format.clearForeground();
- this->editor->setCurrentCharFormat(format);
- }
+ if(checked){
+ QColorDialog dialog(this);
+ connect(&dialog,SIGNAL(colorSelected(const QColor &)),this->editor,SLOT(setTextColor(const QColor &)));
+ connect(&dialog,SIGNAL(rejected()),SLOT(selectionChnged()));
+ dialog.exec();
+ if(this->editor->currentCharFormat().isAnchor()) this->selectionChnged();
+ }else{
+ QTextCharFormat format=this->editor->currentCharFormat();
+ if(format.isAnchor())
+ format.setForeground(QBrush(this->colorset.color(QPalette::Link)));
+ else format.clearForeground();
+ this->editor->setCurrentCharFormat(format);
+ }
}
void RtfEditor::makeLink(bool checked){
- if(checked){
- QInputDialog dialog(this);
- dialog.setWindowTitle("Link to");
- dialog.setLabelText("Link to:");
- dialog.setTextValue("http://");
- connect(&dialog,SIGNAL(textValueSelected(const QString &)),SLOT(setLink(const QString &)));
- connect(&dialog,SIGNAL(rejected()),SLOT(selectionChnged()));
- dialog.exec();
- }else{
- QTextCharFormat format=this->editor->currentCharFormat();
- format.setAnchor(false);
- format.setFontUnderline(false);
- if(format.foreground().color()==colorset.color(QPalette::Link)) format.clearForeground();
- this->editor->setCurrentCharFormat(format);
- }
+ if(checked){
+ QInputDialog dialog(this);
+ dialog.setWindowTitle("Link to");
+ dialog.setLabelText("Link to:");
+ dialog.setTextValue("http://");
+ connect(&dialog,SIGNAL(textValueSelected(const QString &)),SLOT(setLink(const QString &)));
+ connect(&dialog,SIGNAL(rejected()),SLOT(selectionChnged()));
+ dialog.exec();
+ }else{
+ QTextCharFormat format=this->editor->currentCharFormat();
+ format.setAnchor(false);
+ format.setFontUnderline(false);
+ if(format.foreground().color()==colorset.color(QPalette::Link)) format.clearForeground();
+ this->editor->setCurrentCharFormat(format);
+ }
}
void RtfEditor::setLink(const QString &link){
- QUrl link_url(link);
- if(link.isEmpty()){
- this->selectionChnged();
- return;
- }
- if(link_url.scheme().isEmpty()||!link_url.isValid()){
- this->selectionChnged();
- emit invalidLink(link);
- return;
- }
- QTextCharFormat format=this->editor->currentCharFormat();
- format.setAnchorHref(link);
- format.setAnchor(true);
- format.setFontUnderline(true);
- if(format.foreground().color()==this->defaltTextColor)
- format.setForeground(QBrush(colorset.color(QPalette::Link)));
- this->editor->setCurrentCharFormat(format);
+ QUrl link_url(link);
+ if(link.isEmpty()){
+ this->selectionChnged();
+ return;
+ }
+ if(link_url.scheme().isEmpty()||!link_url.isValid()){
+ this->selectionChnged();
+ emit invalidLink(link);
+ return;
+ }
+ QTextCharFormat format=this->editor->currentCharFormat();
+ format.setAnchorHref(link);
+ format.setAnchor(true);
+ format.setFontUnderline(true);
+ if(format.foreground().color()==this->defaltTextColor)
+ format.setForeground(QBrush(colorset.color(QPalette::Link)));
+ this->editor->setCurrentCharFormat(format);
}
QString RtfEditor::html() const{return this->editor->toHtml();}
QString RtfEditor::plain() const{return this->editor->toPlainText();}
void RtfEditor::plain(const QString &str){this->editor->setPlainText(str);}
void RtfEditor::html(const QString &str){this->editor->setPlainText(str);}
void RtfEditor::focusInEvent(QFocusEvent *event){
- this->editor->setFocus();
- event->accept();
+ this->editor->setFocus();
+ event->accept();
}
void RtfEditor::keyPressEvent(QKeyEvent *event){
#ifdef DEBUG
- qDebug()<<hex<<event->modifiers()<<":"<<event->key();
+ qDebug()<<hex<<event->modifiers()<<":"<<event->key();
#endif
- if(event->modifiers()==Qt::ControlModifier&&(event->key()==Qt::Key_Enter||event->key()==Qt::Key_Return)) emit this->sendTriggered();
- event->accept();
+ if(event->modifiers()==Qt::ControlModifier&&(event->key()==Qt::Key_Enter||event->key()==Qt::Key_Return)) emit this->sendTriggered();
+ event->accept();
}
#pragma once
#include <QtGui>
class RtfEditor:virtual public QWidget{
- Q_OBJECT
- Q_PROPERTY(QString html READ html WRITE html)
- Q_PROPERTY(QString plain READ plain WRITE plain)
+ Q_OBJECT
+ Q_PROPERTY(QString html READ html WRITE html)
+ Q_PROPERTY(QString plain READ plain WRITE plain)
public:
- RtfEditor(QWidget *parent=NULL);
+ RtfEditor(QWidget *parent=NULL);
public:
- QString html() const, plain() const;
- void html(const QString &),plain(const QString &);
+ QString html() const, plain() const;
+ void html(const QString &),plain(const QString &);
private slots:
- void selectionChnged();
- void makeBold(bool);
- void makeItalic(bool);
- void makeColor(bool);
- void makeLink(bool);
- void setLink(const QString &link);
+ void selectionChnged();
+ void makeBold(bool);
+ void makeItalic(bool);
+ void makeColor(bool);
+ void makeLink(bool);
+ void setLink(const QString &link);
signals:
- void invalidLink(const QString &link);
- void sendTriggered();
+ void invalidLink(const QString &link);
+ void sendTriggered();
private:
- enum style{Bold,Italic};
- void makeStyle(const style s,bool on);
- //When this widget is focused,To have this->editor focused is needed for convenience.
- void focusInEvent(QFocusEvent *);
- void keyPressEvent(QKeyEvent *);
- QColor defaltTextColor;
- QPalette colorset;
- QAction *bold,*italic,*link,*color;
- QToolBar *toolbar;
- QTextEdit *editor;
- QVBoxLayout *layout;
+ enum style{Bold,Italic};
+ void makeStyle(const style s,bool on);
+ //When this widget is focused,To have this->editor focused is needed for convenience.
+ void focusInEvent(QFocusEvent *);
+ void keyPressEvent(QKeyEvent *);
+ QColor defaltTextColor;
+ QPalette colorset;
+ QAction *bold,*italic,*link,*color;
+ QToolBar *toolbar;
+ QTextEdit *editor;
+ QVBoxLayout *layout;
};
#include "../validator/ipaddressvalidator.h"
SettingDialog::SettingDialog(QWidget *parent):QDialog(parent){
- this->setupUi(this);
- this->setMaximumSize(this->size());
- this->setMinimumSize(this->size());
- this->address->setValidator(new IPAddressValidator(false,this->address));;
- this->setWindowFlags(Qt::Dialog|Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint);
+ this->setupUi(this);
+ this->setMaximumSize(this->size());
+ this->setMinimumSize(this->size());
+ this->address->setValidator(new IPAddressValidator(false,this->address));;
+ this->setWindowFlags(Qt::Dialog|Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint);
}
QHostAddress SettingDialog::IPAddress()const{return QHostAddress(this->address->text());}
void SettingDialog::setIPAddress(const QHostAddress &address){this->address->setText(address.toString());}
void SettingDialog::setNoloadMemberlist(const bool yesno){this->no_load_memberlist->setChecked(yesno);}
void SettingDialog::setTab(const tab id){
- switch(id){
- case SettingDialog::server:
- server:
- this->settingTab->setCurrentIndex(0);
- break;
- case SettingDialog::client:
- this->settingTab->setCurrentIndex(1);
- break;
- case SettingDialog::misc:
- this->settingTab->setCurrentIndex(2);
- break;
- default:
- goto server;
- }
+ switch(id){
+ case SettingDialog::server:
+ server:
+ this->settingTab->setCurrentIndex(0);
+ break;
+ case SettingDialog::client:
+ this->settingTab->setCurrentIndex(1);
+ break;
+ case SettingDialog::misc:
+ this->settingTab->setCurrentIndex(2);
+ break;
+ default:
+ goto server;
+ }
}
void SettingDialog::setTabEnabled(const tab id,bool enable){
- switch(id){
- case SettingDialog::server:
- server:
- this->settingTab->setTabEnabled(0,enable);
- break;
- case SettingDialog::client:
- this->settingTab->setTabEnabled(1,enable);
- break;
- case SettingDialog::misc:
- this->settingTab->setTabEnabled(2,enable);
- break;
- default:
- goto server;
- }
+ switch(id){
+ case SettingDialog::server:
+ server:
+ this->settingTab->setTabEnabled(0,enable);
+ break;
+ case SettingDialog::client:
+ this->settingTab->setTabEnabled(1,enable);
+ break;
+ case SettingDialog::misc:
+ this->settingTab->setTabEnabled(2,enable);
+ break;
+ default:
+ goto server;
+ }
}
void SettingDialog::setAddressAndPort(AddressAndPort pair){
- this->setIPAddress(pair.first);
- this->setPort(pair.second);
+ this->setIPAddress(pair.first);
+ this->setPort(pair.second);
}
#include "ui_settings.h"
#include "../definition.h"
class SettingDialog:virtual public QDialog,virtual private Ui::settingDialogBase{
- Q_OBJECT
+ Q_OBJECT
public:
- enum tab{server,client,misc};
- SettingDialog(QWidget *parent=NULL);
- QHostAddress IPAddress()const;
- quint16 port()const;
- AddressAndPort addressPort()const;
- QString nickName()const;
- bool noloadMemberlist()const;
+ enum tab{server,client,misc};
+ SettingDialog(QWidget *parent=NULL);
+ QHostAddress IPAddress()const;
+ quint16 port()const;
+ AddressAndPort addressPort()const;
+ QString nickName()const;
+ bool noloadMemberlist()const;
public slots:
- void setPort(const quint16 port);
- void setAddressAndPort(const AddressAndPort pair);
- void setIPAddress(const QHostAddress &address);
- void setNickName(const QString &);
- void setNoloadMemberlist(const bool);
- void setTab(const tab id);
- void setTabEnabled(const tab id,bool enable);
+ void setPort(const quint16 port);
+ void setAddressAndPort(const AddressAndPort pair);
+ void setIPAddress(const QHostAddress &address);
+ void setNickName(const QString &);
+ void setNoloadMemberlist(const bool);
+ void setTab(const tab id);
+ void setTabEnabled(const tab id,bool enable);
};
//This supports IPv4 only. I'll reimplement it soon.
IPAddressValidator::IPAddressValidator(bool check_port, QObject *parent):
QRegExpValidator(QRegExp(QString("\\b(?:(?:%1)\\.){3}(?:%1)\\b").arg("25[0-5]|2[0-4]\\d{1}|1\\d\\d?|[2-9]\\d?|[01]")),parent){
- if(check_port){
- QString pattern=this->regExp().pattern()+
- ":(?:6553[1-5]{1}|65[1-4]{1}\\d{2}|6[1-4]\\d{3}|[1-5]\\d{4}|\\d{1,4})";
- this->setRegExp(QRegExp(pattern));
- }
+ if(check_port){
+ QString pattern=this->regExp().pattern()+
+ ":(?:6553[1-5]{1}|65[1-4]{1}\\d{2}|6[1-4]\\d{3}|[1-5]\\d{4}|\\d{1,4})";
+ this->setRegExp(QRegExp(pattern));
+ }
}
class IPAddressValidator : virtual public QRegExpValidator{
public:
- IPAddressValidator(bool check_port,QObject *parent=NULL);
+ IPAddressValidator(bool check_port,QObject *parent=NULL);
};