diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 index e8f9be9..82a6259 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.gitignore +docs + # C++ objects and libs *.slo *.lo @@ -51,6 +54,9 @@ compile_commands.json # QtCreator local machine specific files for imported projects *creator.user* +#vscode +.vscode + # build build build-* diff --git a/README.md b/README.md index 04670c2..bf49ceb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ -# kylin-ipmsg +# kylin-messages Provide text chat and file transfer function with no server. -## Dependencies -* sudo apt install wmctrl diff --git a/buddylistitemmodel.cpp b/buddylistitemmodel.cpp deleted file mode 100644 index 1b5fc46..0000000 --- a/buddylistitemmodel.cpp +++ /dev/null @@ -1,349 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "buddylistitemmodel.h" -#include "platform.h" -#include "peer.h" -#include "settings.h" - -BuddyListItemModel::BuddyListItemModel() : - QStandardItemModel(NULL), mSettings(NULL) -{ - QHash roleNames; - roleNames[Ip] = "ip"; - roleNames[Port] = "port"; - roleNames[Iptext] = "iptext"; - roleNames[Username] = "username"; - roleNames[System] = "system"; - roleNames[Platform] = "platform"; - roleNames[GenericAvatar] = "generic"; - roleNames[Avatar] = "avatar"; - roleNames[OsLogo] = "oslogo"; - roleNames[ShowBack] = "showback"; - roleNames[ShowMsgAnim] = "showMsgAnim"; - setItemRoleNames(roleNames); - - // 设置中心 - mSettings = new Settings(this); -} - -// 增加本机信息 -/* -* Parameters: -* text1: msg text -* -* Return : -*/ -void BuddyListItemModel::addMeElement(QString text1) -{ -// QString nickname = mSettings->nickname("MAC"); -// QString username = Platform::getSystemUsername() + text1; -// if (nickname != "error" && nickname != "") -// username = nickname; - addBuddy("", - 0, - Platform::getSystemUsername() + text1, - Platform::getHostname(), - "MAC", - Platform::getPlatformName(), - QUrl::fromLocalFile(Platform::getAvatarPath())); -} - -// 增加IP发送信息 -/* -* Parameters: -* text1: msg1 -* text2: msg2 -* Return : -*/ -void BuddyListItemModel::addIpElement(QString text1, QString text2) -{ - addBuddy("IP", - 0, - text1, - text2, - "MAC", - "IP", - QUrl("")); -} - -// 增加好友 -/* -* Parameters: -* ip: ip address -* port: port -* username: user name -* system: os system -* mac: mac address -* platform: os platform -* avatarpath: user avatar picture path -* Return : -*/ -void BuddyListItemModel::addBuddy(QString ip, qint16 port, QString username, QString system, QString mac, QString platform, QUrl avatarPath) -{ -// qDebug()<<"!! addbuddy: "<setData(ip, BuddyListItemModel::Ip); - }else{ - it->setData(ip + " " + mac, BuddyListItemModel::Ip); - } - it->setData(port, BuddyListItemModel::Port); - it->setData(false, BuddyListItemModel::ShowBack); - it->setData(false, BuddyListItemModel::ShowMsgAnim); - - // Set (or update) data - // 如果有备注名,则显示备注名, show nickname - QString nickname = mSettings->nickname(mac); - if (nickname != "error" && nickname != "") - username = nickname; - it->setData(username, BuddyListItemModel::Username); - it->setData(mac, BuddyListItemModel::Mac); - - if (ip != "IP" && ip != ""){ - it->setData(ip + " ", BuddyListItemModel::Iptext); - it->setData("" + mac, BuddyListItemModel::System); - }else{ - it->setData("", BuddyListItemModel::Iptext); - it->setData("" + system, BuddyListItemModel::System); - } - - it->setData(platform, BuddyListItemModel::Platform); - - // 将好友头像保存在文件夹中 - // if (ip != "" && ip != "IP" && ip != "127.0.0.1") { - // QDir *fileDir = new QDir; - - // QString filePath = QString(getenv("HOME")) + "/.ipmsgFiles"; - // QString fileName = filePath + "/" + ip + ".png"; - - // if (!(fileDir->exists(filePath))) { - // fileDir->mkdir(filePath); - // } - - // qDebug() << downloadUrl(avatarPath.toString(), fileName); - - // // qml访问本地图片需使用绝对路径 - // it->setData(QUrl("file://" + fileName), BuddyListItemModel::Avatar); - // } - // else { - // it->setData(avatarPath, BuddyListItemModel::Avatar); - // } - - // 禁用获取好友头像功能,防止龙芯架构下的闪退问题 - it->setData(QUrl(""), BuddyListItemModel::Avatar); - - // Update generic avatar - if ((platform.toLower() == "symbian") || (platform.toLower() == "android") || (platform.toLower() == "ios") || (platform.toLower() == "blackberry") || (platform.toLower() == "windowsphone")) - it->setData("SmartphoneLogo.png", BuddyListItemModel::GenericAvatar); - else if (platform.toLower() == "ip") - it->setData("IpLogo.png", BuddyListItemModel::GenericAvatar); - else - it->setData("PcLogo.png", BuddyListItemModel::GenericAvatar); - - // Update logo - if (platform.toLower() == "windows"){ - it->setData("WindowsLogo.png", BuddyListItemModel::OsLogo); - it->setData("WindowsLogo.png", BuddyListItemModel::GenericAvatar); - } - else if (platform.toLower() == "macintosh"){ - it->setData("AppleLogo.png", BuddyListItemModel::OsLogo); - it->setData("AppleLogo.png", BuddyListItemModel::GenericAvatar); - } - else if (platform.toLower() == "linux"){ - it->setData("LinuxLogo.png", BuddyListItemModel::OsLogo); - it->setData("LinuxLogo.png", BuddyListItemModel::GenericAvatar); - } - else if (platform.toLower() == "symbian"){ - it->setData("SymbianLogo.png", BuddyListItemModel::OsLogo); - it->setData("SymbianLogo.png", BuddyListItemModel::GenericAvatar); - } - else if (platform.toLower() == "ios"){ - it->setData("IosLogo.png", BuddyListItemModel::OsLogo); - it->setData("IosLogo.png", BuddyListItemModel::GenericAvatar); - } - else if (platform.toLower() == "windowsphone"){ - it->setData("WindowsPhoneLogo.png", BuddyListItemModel::OsLogo); - it->setData("WindowsPhoneLogo.png", BuddyListItemModel::GenericAvatar); - } - else if (platform.toLower() == "blackberry"){ - it->setData("BlackberryLogo.png", BuddyListItemModel::OsLogo); - it->setData("BlackberryLogo.png", BuddyListItemModel::GenericAvatar); - } - else if (platform.toLower() == "android"){ - it->setData("AndroidLogo.png", BuddyListItemModel::OsLogo); - it->setData("AndroidLogo.png", BuddyListItemModel::GenericAvatar); - } - else{ - it->setData("UnknownLogo.png", BuddyListItemModel::OsLogo); - it->setData("UnknownLogo.png", BuddyListItemModel::GenericAvatar); - } - } - if (add) { - appendRow(it); - if (ip != ""){ - mIpsMap.insert(mac, ip + " " + mac); - mItemsMap.insert(ip + " " + mac, it); - } - else - mMeItem = it; - } -} - -// 增加好友 -/* -* Parameters: -* peer: peer struct -* Return : -*/ -void BuddyListItemModel::addBuddy(Peer &peer) -{ - QUrl avatarPath = QUrl("http://" + peer.address.toString() + ":" + QString::number(peer.port + 1) + "/dukto/avatar"); - - addBuddy(peer.address.toString(), - peer.port, - peer.username, - peer.system, - peer.mac, - peer.platform, - avatarPath); -} - -// 删除好友 -/* -* Parameters: -* mac: mac address -* Return : -*/ -void BuddyListItemModel::removeBuddy(QString mac) -{ - if (!mIpsMap.contains(mac)) return; - QString ip = mIpsMap.value(mac); - - QStandardItem* it = mItemsMap[ip]; - - mItemsMap.remove(ip); - this->removeRow(this->indexFromItem(it).row()); -} - -/* -* Summary: show single back -* Parameters: -* idx: index -* Return : -*/ -void BuddyListItemModel::showSingleBack(int idx) -{ - for (int i = 0; i < rowCount(); i++) - itemFromIndex(index(i, 0))->setData(false, BuddyListItemModel::ShowBack); - itemFromIndex(index(idx, 0))->setData(true, BuddyListItemModel::ShowBack); -} - -// 通过IP地址查找好友名字 -/* -* Parameters: -* ip: ip address -* Return : -*/ -QString BuddyListItemModel::buddyNameByIp(QString ip) -{ - if (!mItemsMap.contains(ip)) return ""; - return mItemsMap.value(ip)->data(BuddyListItemModel::Username).toString(); -} - -// 通过IP地址查找好友 -/* -* Parameters: -* ip: ip address -* Return : -*/ -QStandardItem* BuddyListItemModel::buddyByIp(QString ip) -{ - if (!mItemsMap.contains(ip)) return NULL; - return mItemsMap.value(ip); -} - -// 通过mac查找好友 -/* -* Parameters: -* mac: mac address -* Return : -*/ -QStandardItem* BuddyListItemModel::buddyByMac(QString mac){ - if (!mIpsMap.contains(mac)) return NULL; - return mItemsMap.value(mIpsMap.value(mac)); -} - -/* -* Summary: first friend ip -* Return : -*/ -QString BuddyListItemModel::fistBuddyIp() -{ - if (this->rowCount() < 3) return ""; - return this->index(2, 0).data(BuddyListItemModel::Ip).toString(); -} - -// 下载头像到本地 -bool BuddyListItemModel::downloadUrl(const QString &url, const QString &fileName) -{ - QNetworkAccessManager manager; - QNetworkRequest request; - request.setUrl(url); - QNetworkReply *reply = manager.get(request); - - QEventLoop loop; - connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); - loop.exec(); - - if (reply->error() != QNetworkReply::NoError) { - return false; - } - - QFile file(fileName); - qDebug() << "fileName " << fileName; - if (!file.open(QIODevice::WriteOnly)) { - return false; - } - file.write(reply->readAll()); - - file.close(); - delete reply; - return true; -} - -/* -* Summary: update my element -* Return : -*/ -void BuddyListItemModel::updateMeElement() -{ - mMeItem->setData(Platform::getSystemUsername(), BuddyListItemModel::Username); -} diff --git a/buddylistitemmodel.h b/buddylistitemmodel.h deleted file mode 100644 index 0ec51ce..0000000 --- a/buddylistitemmodel.h +++ /dev/null @@ -1,89 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef BUDDYLISTITEMMODEL_H -#define BUDDYLISTITEMMODEL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class Peer; -class QUrl; -class Settings; - -class BuddyListItemModel : public QStandardItemModel -{ -public: - BuddyListItemModel(); - void addMeElement(QString text1); - void addIpElement(QString text1, QString text2); - void addBuddy(QString ip, qint16 port, QString username, QString system, QString mac, QString platform, QUrl avatarPath); - void addBuddy(Peer& peer); - void removeBuddy(QString mac); - void showSingleBack(int idx); - void updateMeElement(); - QString buddyNameByIp(QString ip); - QStandardItem* buddyByIp(QString ip); - QStandardItem* buddyByMac(QString mac); - QString fistBuddyIp(); - - // 下载头像到本地 - bool downloadUrl(const QString &url, const QString &fileName); - - inline Settings* settings() { return mSettings; } - - enum BuddyRoles { - Ip = Qt::UserRole + 1, - Port, - Iptext, - Username, - System, - Mac, - Platform, - GenericAvatar, - Avatar, - OsLogo, - ShowBack, - ShowMsgAnim, - }; - - /*<"ip mac" , QStandardItem *>*/ - QHash mItemsMap; - /*<"mac" , "ip mac">*/ - QHash mIpsMap; - QStandardItem* mMeItem; - -private: - Settings *mSettings; -}; - -#endif // BUDDYLISTITEMMODEL_H diff --git a/chatwidget.cpp b/chatwidget.cpp deleted file mode 100644 index 168ccc7..0000000 --- a/chatwidget.cpp +++ /dev/null @@ -1,869 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "chatwidget.h" -#include "ui_chatwidget.h" -#include "settings.h" -#include "ipaddressitemmodel.h" -#include "buddylistitemmodel.h" - -/* -* Summary: chat widget logic -*/ -ChatWidget::ChatWidget(QDialog *parent) : QDialog(parent), ui(new Ui::ChatWidget), mSettings(NULL){ - ui->setupUi(this); - - // 设置中心 - mSettings = new Settings(this); - // 响应用户手册 - mDaemonIpcDbus = new DaemonIpcDbus(); - - // 设置“添加备注”按钮大小 - QString locale = QLocale::system().name(); - if(locale == "zh_CN"){ - ui->pb_addname->setFixedWidth(90); - ui->pb_checkname->setFixedWidth(90); - ui->pb_sendmsg->setFixedWidth(120); - } - -// this->setWindowIcon(QIcon("/usr/share/pixmaps/kylin-ipmsg.png")); - QString iconPath = mSettings->iconPath(); - if (iconPath == "") { - iconPath = "/usr/share/pixmaps/kylin-ipmsg.png"; - } -// setWindowIcon(QIcon(iconPath)); - setWindowIcon(QIcon::fromTheme("kylin-ipmsg")); - - this->setMaximumSize(QSize(450,480)); - this->setMinimumSize(QSize(450,480)); - this->setWindowFlags(Qt::FramelessWindowHint); - - this->ui->te_chatlog->setReadOnly(true); - this->ui->pb_titleicon->setFocusPolicy(Qt::NoFocus); - this->ui->pb_sendmsg->setFocusPolicy(Qt::NoFocus); - this->ui->pb_sendfile->setFocusPolicy(Qt::NoFocus); - this->ui->pb_senddir->setFocusPolicy(Qt::NoFocus); - this->ui->pb_w_cancel->setFocusPolicy(Qt::NoFocus); - this->ui->pbar_transfer->setFocusPolicy(Qt::NoFocus); - this->ui->pbar_transfer_recv->setFocusPolicy(Qt::NoFocus); - - this->ui->pb_sendmsg->setEnabled(false); - - this->ui->te_chatlog->setOpenExternalLinks(false); - this->ui->te_chatlog->setOpenLinks(false); - - this->connect(this->ui->le_ip, SIGNAL(textChanged(QString)), this, SLOT(leTextChanged(QString))); - this->connect(this->ui->te_chat, SIGNAL(textChanged()), this, SLOT(teTextChanged())); - this->connect(this->ui->te_chatlog, SIGNAL(anchorClicked(QUrl)), this, SLOT(openUrl(QUrl))); - - // caoliang 给添加备注和确认修改按钮注册事件 - this->connect(this->ui->pb_addname,SIGNAL(clicked()),this,SLOT(on_pb_addname_clicked()),Qt::UniqueConnection); - this->connect(this->ui->pb_checkname,SIGNAL(clicked()),this,SLOT(on_pb_checkname_clicked()),Qt::UniqueConnection); - - this->ui->te_chat->installEventFilter(this); - this->ui->te_chatlog->installEventFilter(this); - this->ui->le_ip->installEventFilter(this); - - this->timeFlag = 0; - this->alertTimer = new QTimer(this); - this->alertTimer->setInterval(300); - this->connect(this->alertTimer, SIGNAL(timeout()), this, SLOT(msgAlert())); - -// this->iconDukto = QIcon("/usr/share/pixmaps/kylin-ipmsg.png"); - this->iconDukto = QIcon::fromTheme("kylin-ipmsg"); - this->iconBlank = QIcon(":/qml/dukto/Blank.png"); - - this->dbuddy = new DestinationBuddy(this); - - this->ui->lb_bottomshadow->hide(); - this->ui->pbar_transfer->setTextVisible(false); - this->ui->pbar_transfer->setRange(0, 100); - this->ui->pbar_transfer->reset(); - this->ui->w_progress->hide(); - - this->ui->pbar_transfer_recv->setTextVisible(false); - this->ui->pbar_transfer_recv->setRange(0, 100); - this->ui->pbar_transfer_recv->reset(); - this->ui->w_progress_recv->hide(); - - this->ui->w_alert->hide(); - - this->isOnLine = false; - this->sendType = ChatWidget::Idle; -} - -ChatWidget::~ChatWidget(){ - delete ui; -} - -// 事件过滤器 -/* -* Summary: filter all event -* Parameters: -* o: object -* e: event -* Return : -*/ -bool ChatWidget::eventFilter(QObject *o, QEvent *e){ - if(e->type() == QEvent::FocusIn){ - this->focusIn(); - }else if(e->type() == QEvent::FocusOut){ - this->focusOut(); - - } - - else if(e->type() == QEvent::KeyPress){ - QKeyEvent *ke = static_cast(e); - // ctrl+enter换行 - if((ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) && (ke->modifiers() & Qt::ControlModifier)){ - this->ui->te_chat->insertPlainText("\n"); - return true; - // enter发送消息 - }else if(ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter){ - if(this->ui->pb_sendmsg->isEnabled() == true && this->ui->pb_sendmsg->isHidden() == false){ - this->on_pb_sendmsg_clicked(); - } - return true; - } - } - return false; -} - -/* -* Summary: focus in event -* Parameters: -* -* Return : -*/ -void ChatWidget::focusIn(){ - this->isFocus = true; - this->alertTimer->stop(); - this->setWindowIcon(this->iconDukto); - this->ui->noFocusDiv->hide(); -} - -/* -* Summary: focus out event -* Parameters: -* -* Return : -*/ -void ChatWidget::focusOut(){ - this->isFocus = false; - this->ui->noFocusDiv->show(); -} - -// 初始化界面布局和类型等 -/* -* -* Return : -*/ -void ChatWidget::firstStyle(){ - this->ip = this->dbuddy->ip(); - this->ui->le_nickname->hide(); //caoliang 初始化隐藏le_nickname输入框 - this->ui->pb_checkname->hide(); // caoliang 初始化隐藏按钮 - // 输入IP的对话窗口 - if(this->dbuddy->ip() == "IP MAC"){ - this->ui->lb_name->setText(tr("The Remote IP Addr")); - // - this->ui->lb_name->setFixedWidth(180); - - this->ui->lb_machine->hide(); - this->ui->le_ip->setEnabled(true); - this->ui->le_ip->show(); - this->ui->le_ip->setFocus(); - - this->ui->pb_addname->hide(); //在输入IP的对话窗口隐藏修改备注按钮 - - this->ui->pb_sendmsg->hide(); - this->ui->pb_sendfile->hide(); - this->ui->pb_senddir->hide(); - this->ui->te_chat->setEnabled(false); - - this->dbuddy->mUsername = "? ? ?"; - this->dbuddy->mSystem = "? ? ? ?"; - this->dbuddy->mPlatform = "unknown"; - this->dbuddy->mAvatar = ""; - }else{ - this->ui->lb_name->setText(this->dbuddy->username()); - this->ui->lb_machine->setText(this->dbuddy->system()); - this->ui->lb_machine->show(); - this->ui->le_ip->setEnabled(false); - this->ui->le_ip->hide(); - - if(this->ui->lb_name->text() == "? ? ?"){ - this->ui->lb_name->setText(this->ip.split(" ")[0]); - } - } - - this->setWindowTitle(tr("Kylin Ipmsg") + this->ip); -// this->setWindowTitle("麒麟传书" + this->ip); - this->ui->pb_titleicon->setStyleSheet("QPushButton{border: 0px solid; background-image: url(':/qml/dukto/BackIconDark.png');}"); - this->ui->lb_head->setStyleSheet("QLabel{background-image: url(':/qml/dukto/" + dbuddy->osLogo() + "');}"); - this->ui->lb_name->setStyleSheet("QLabel{color: " + this->theme->color4() + ";font-size:18px;}"); - this->ui->lb_machine->setStyleSheet("QLabel{color: " + this->theme->color4() + ";font-size:18px;}"); - this->ui->noFocusDiv->setStyleSheet("QLabel{background-color:rgba(120,120,120,20%);}"); - this->ui->lb_topshadow->setStyleSheet("QLabel{background-image: url(':/qml/dukto/BottomShadow.png');}"); - this->ui->lb_bottomshadow->setStyleSheet("QLabel{background-image: url(':/qml/dukto/TopShadow.png');}"); - this->ui->lb_bottomshadow_recv->setStyleSheet("QLabel{background-image: url(':/qml/dukto/TopShadow.png');}"); -} - -// 根据主题显示现有窗口 -void ChatWidget::showme(){ - this->setStyleSheet("QDialog{border:2px solid " + this->theme->color3() + "; background-color: white;}"); - this->ui->lb_title->setStyleSheet("QLabel{color: " + this->theme->color2() + ";font-size:24px;}"); - this->ui->le_ip->setStyleSheet("QLineEdit{color: " + this->theme->color4() + "; border: 1px solid " + this->theme->color3() + ";font-size:18px;}"); - this->ui->te_chatlog->setStyleSheet("QTextBrowser{border: " + this->theme->color3() + ";font-size:18px;}"); - this->ui->te_chat->setStyleSheet("QTextEdit{border: 1px solid " + this->theme->color3() + ";font-size:18px;}"); - this->ui->pb_sendmsg->setStyleSheet( "QPushButton{border: 2px solid " + this->theme->color2() + "; color: "+this->theme->color2()+";font-size:16px;}"); - this->ui->pb_sendfile->setStyleSheet("QPushButton{border: 2px solid " + this->theme->color2() + "; color: "+this->theme->color2()+";font-size:16px;}"); - this->ui->pb_senddir->setStyleSheet( "QPushButton{border: 2px solid " + this->theme->color2() + "; color: "+this->theme->color2()+";font-size:16px;}"); - this->ui->lb_head_bg->setStyleSheet( "QLabel{background-color: " + this->theme->color3() + "}"); - - this->ui->lb_w_title->setStyleSheet("QLabel{color: " + this->theme->color6() + ";font-size:18px;}"); - this->ui->lb_w_text->setStyleSheet( "QLabel{color: " + this->theme->color6() + ";font-size:18px;}"); - this->ui->pb_w_cancel->setStyleSheet("QPushButton{border: 2px solid " + this->theme->color6() + "; color: " + this->theme->color6() + ";font-size:16px;}"); - this->ui->w_p_center->setStyleSheet("QWidget#w_p_center{background-color: " + this->theme->color2() + ";}"); - this->ui->pbar_transfer->setStyleSheet("QProgressBar{background-color: " + this->theme->color3() + "; border: 0px; border-radius: 0px;}" - "QProgressBar:chunk{background-color: " + this->theme->color6() + ";}"); - this->ui->pbar_chunk->setStyleSheet("QLabel{background-color: " + this->theme->color6() + ";}"); - - this->ui->lb_w_title_recv->setStyleSheet("QLabel{color: " + this->theme->color6() + ";font-size:18px;}"); - this->ui->lb_w_text_recv->setStyleSheet( "QLabel{color: " + this->theme->color6() + ";font-size:18px;}"); - this->ui->w_p_center_recv->setStyleSheet("QWidget#w_p_center_recv{background-color: " + this->theme->color2() + ";}"); - this->ui->pbar_transfer_recv->setStyleSheet("QProgressBar{background-color: " + this->theme->color3() + "; border: 0px; border-radius: 0px;}" - "QProgressBar:chunk{background-color: " + this->theme->color6() + ";}"); - this->ui->pbar_chunk_recv->setStyleSheet("QLabel{background-color: " + this->theme->color6() + ";}"); - - this->ui->w_alert->setStyleSheet("QWidget#w_alert{background-color: " + this->theme->color2() + ";}"); - this->ui->lb_alert->setStyleSheet("QLabel{color: " + this->theme->color6() + ";font-size:18px;}"); - - // coaliang - this->ui->pb_addname->setStyleSheet("QPushButton{border: 2px solid " + this->theme->color2() + "; color: "+this->theme->color2()+";font-size:16px;}"); - this->ui->le_nickname->setStyleSheet("QLineEdit{color: " + this->theme->color4() + "; border: 1px solid " + this->theme->color3() + ";font-size:18px;}"); - this->ui->pb_checkname->setStyleSheet("QPushButton{border: 2px solid " + this->theme->color2() + "; color: "+this->theme->color2()+";font-size:16px;}"); - -// this->show(); -} - -// 不处理格式,直接添加传入的内容到聊天记录栏 -/* -* Parameters: -* text: set text msg into chat widget -* Return : -*/ -void ChatWidget::addLogDirect(QString text){ - this->ui->te_chatlog->append(text); - - if(this->isFocus == false){ - this->alertTimer->start(); - } -} - -// 处理格式,添加一条文字记录到聊天记录栏 -/* -* Parameters: -* text: text msg -* Return : -*/ -void ChatWidget::addTextLog(QString text){ - QDateTime time = QDateTime::currentDateTime(); - QString alog = ""; - alog += this->dbuddy->username(); - alog += " ("; - alog += time.toString("hh:mm:ss"); - alog += ")"; - this->ui->te_chatlog->append(alog); - this->ui->te_chatlog->append("" + text + ""); - - if(this->isFocus == false){ - this->alertTimer->start(); - } -} - -// 一次发送操作完成 -void ChatWidget::onSendCompleted(){ - if(this->sendType != ChatWidget::Idle){ - // 发送成功代表输入的 IP 地址有效,锁定 IP 输入框,固化本聊天窗口 - if(this->ui->le_ip->isEnabled() == true){ - this->ui->le_ip->setEnabled(false); - this->ui->le_ip->hide(); -// this->ui->lb_name->setText("对方的 IP Mac"); - this->ui->lb_name->setText(tr("Show Remote IP Addr")); - this->ui->lb_machine->setText(this->ip); - this->ui->lb_machine->show(); - this->setWindowTitle(tr("Kylin Ipmsg") + this->ip); -// this->setWindowTitle("麒麟传书" + this->ip); - - emit reSaveCw(this->ip.split(" ")[1]); - } - - QDateTime time = QDateTime::currentDateTime(); - QString alog = ""; - alog += tr("Me"); -// alog += "我"; - alog += " ("; - alog += time.toString("hh:mm:ss"); - alog += ")"; - this->ui->te_chatlog->append(alog); - - if(this->sendType == ChatWidget::Text){ - this->ui->te_chatlog->append("" + this->ui->te_chat->toPlainText() + ""); - this->ui->te_chat->clear(); - } - if(this->sendType == ChatWidget::Files){ - this->ui->te_chatlog->append("" + tr("file sent out") + ""); -// this->ui->te_chatlog->append("" + "发送了文件" + ""); - this->stopTransfer(true); - } - if(this->sendType == ChatWidget::Dir){ - this->ui->te_chatlog->append("" + tr("dir sent out") + ""); -// this->ui->te_chatlog->append("" + "发送了文件夹" + ""); - this->stopTransfer(true); - } - - this->enableInput(); - this->ui->lb_alert->setText(""); - this->ui->w_alert->hide(); - - this->sendType = ChatWidget::Idle; - - - } -} - -// IP输入框格式判断 -/* -* Parameters: -* text: change text -* Return : -*/ -void ChatWidget::leTextChanged(QString text){ - this->ui->lb_alert->setText(""); - this->ui->w_alert->hide(); - // IPv4地址格式正则匹配符 - QRegExp rx("((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))"); - text = this->ui->le_ip->text().trimmed(); - bool match = rx.exactMatch(text); - - if(match == true){ - bool isExist = false; - for (int i = 0; i < this->buddies->keys().size(); i ++){ - QStandardItem *item = this->buddies->value(this->buddies->keys().at(i)); - if(text == item->data(BuddyListItemModel::Iptext).toString().trimmed()){ - isExist = true; - } - } - - if(isExist == false){ - if(text == this->myIp){ - this->ui->pb_sendmsg->hide(); - this->ui->pb_sendfile->hide(); - this->ui->pb_senddir->hide(); - this->ui->te_chat->setEnabled(false); - this->ui->lb_alert->setText(tr("This is your Ip Addr")); -// this->ui->lb_alert->setText("这是你自己的IP地址"); - this->ui->w_alert->show(); - }else{ - this->ui->pb_sendmsg->show(); - this->ui->pb_sendfile->show(); - this->ui->pb_senddir->show(); - this->ui->te_chat->setEnabled(true); - - // 主动连接情况下,目标IP只可能对应一台机器,所以mac设置为和IP相同 - // 被动连接则不同,一个来源IP可能对应一个下级网络的多台机器 - this->dbuddy->mIp = text + " " + text; - this->ip = text + " " + text; - } - - // 已有该 IP 好友 - }else{ - this->ui->pb_sendmsg->hide(); - this->ui->pb_sendfile->hide(); - this->ui->pb_senddir->hide(); - this->ui->te_chat->setEnabled(false); - this->ui->lb_alert->setText(tr("IP already exist in buddies")); -// this->ui->lb_alert->setText("已有该IP好友,请点击好友打开聊天界面"); - this->ui->w_alert->show(); - } - - }else{ - this->ui->pb_sendmsg->hide(); - this->ui->pb_sendfile->hide(); - this->ui->pb_senddir->hide(); - this->ui->te_chat->setEnabled(false); - this->ui->lb_alert->setText(tr("Illegal IP address")); -// this->ui->lb_alert->setText("输入的IP地址不合法"); - this->ui->w_alert->show(); - } -} - -// 输入 IP 模式时判断好友是否存在 -bool ChatWidget::isIpExists(){ - if(this->ui->le_ip->isEnabled() == true){ - QString text = this->ui->le_ip->text(); - bool isExist = false; - - for (int i = 0; i < this->buddies->keys().size(); i ++){ - QStandardItem *item = this->buddies->value(this->buddies->keys().at(i)); - if(text == item->data(BuddyListItemModel::Iptext).toString().trimmed()){ - isExist = true; - } - } - - // 已有该 IP 好友 - if(isExist == true){ - this->ui->pb_sendmsg->hide(); - this->ui->pb_sendfile->hide(); - this->ui->pb_senddir->hide(); - this->ui->te_chat->setEnabled(false); - this->ui->lb_alert->setText(tr("IP already exist in buddies")); -// this->ui->lb_alert->setText("已有该IP好友,请点击好友打开聊天界面"); - this->ui->w_alert->show(); - - return true; - - // 没有该 IP 好友 - }else{ - return false; - } - - // 不是 IP 模式 - }else{ - return false; - } -} - -/* -* Summary: text changed event -* Return : -*/ -void ChatWidget::teTextChanged(){ - // 空消息判断 - QString text = this->ui->te_chat->toPlainText().trimmed(); - if(text == ""){ - this->ui->pb_sendmsg->setEnabled(false); - }else{ - if(this->ui->pb_sendmsg->isHidden() == true){ - this->ui->pb_sendmsg->show(); - } - this->ui->pb_sendmsg->setEnabled(true); - } - - // 限制单次最大发送字数 - QString strText = this->ui->te_chat->toPlainText(); - int length = strText.count(); - if(length > MAXINPUTLEN){ - int position = this->ui->te_chat->textCursor().position(); - strText.remove(position - (length - MAXINPUTLEN), length - MAXINPUTLEN); - this->ui->te_chat->setText(strText); - QTextCursor cursor = this->ui->te_chat->textCursor(); - cursor.setPosition(position - (length - MAXINPUTLEN)); - this->ui->te_chat->setTextCursor(cursor); - } -} - -/* -* Summary: enable input event -* Return : -*/ -void ChatWidget::enableInput(){ - if(this->sendType != ChatWidget::Idle){ - if(this->ui->te_chat->toPlainText().trimmed() != ""){ - this->ui->pb_sendmsg->setEnabled(true); - } - this->ui->pb_sendfile->setEnabled(true); - this->ui->pb_senddir->setEnabled(true); - this->ui->te_chat->setEnabled(true); - this->ui->te_chat->setFocus(); - - this->sendType = ChatWidget::Idle; - } -} - -/* -* Summary: disable input event -* Return : -*/ -void ChatWidget::disableInput(){ - this->ui->te_chat->setEnabled(false); - this->ui->pb_sendmsg->setEnabled(false); - this->ui->pb_sendfile->setEnabled(false); - this->ui->pb_senddir->setEnabled(false); -} - -// 开始数据传输,true为发送,false为接收 -void ChatWidget::startTransfer(bool isSend){ - if(isSend == true){ - this->ui->w_progress->show(); - this->disableInput(); - }else{ - this->ui->w_progress_recv->show(); - } -} - -// 传输状态更新,true为发送,false为接收 -void ChatWidget::updateTransferStatus(int percent, QString text, bool isSend){ - if(percent != 0){ - int len = 412 * percent / 100; - - if(isSend == true){ - this->ui->pbar_chunk->resize(len, 45); - this->ui->lb_w_text->setText(text); - } - else{ - this->ui->pbar_chunk_recv->resize(len, 45); - this->ui->lb_w_text_recv->setText(text); - } - } -} - -// 结束数据传输,true为发送,false为接收 -void ChatWidget::stopTransfer(bool isSend){ - if(isSend == true){ - this->ui->pbar_chunk->resize(0, 0); - this->ui->lb_w_text->setText(""); - this->ui->w_progress->hide(); - this->enableInput(); - } - else{ - this->ui->pbar_chunk_recv->resize(0, 0); - this->ui->lb_w_text_recv->setText(""); - this->ui->w_progress_recv->hide(); - } -} - -// 取消接收数据 -void ChatWidget::recvCancel(){ - this->stopTransfer(false); - this->addTextLog(tr("Remoter has stoped the transfer")); -// this->addTextLog("对方中止了文件传输"); -} - -// 点击发送文字 -void ChatWidget::on_pb_sendmsg_clicked(){ - if(this->isIpExists() == false){ - this->sendType = ChatWidget::Text; - - this->disableInput(); - - textToSend = this->ui->te_chat->toPlainText(); - - if(this->isOnLine == true){ - emit sendMsg(textToSend); - - // 断线重连 - }else{ - this->slotTransferMsg(TRY_RECONN); - emit reBindSocket(this); - } - } - else{ - this->focusIn(); - } -} - -// 点击发送文件 -void ChatWidget::on_pb_sendfile_clicked(){ - if(this->isIpExists() == false){ - this->sendType = ChatWidget::Files; - - fileToSend = QFileDialog::getOpenFileNames(this, tr("pls choose files to send")); -// fileToSend = QFileDialog::getOpenFileNames(this, "请选择要发送的文件"); - - if (fileToSend.count() != 0) { - this->disableInput(); - - if(this->isOnLine == true){ - emit sendFiles(fileToSend); - - // 断线重连 - }else{ - this->slotTransferMsg(TRY_RECONN); - emit reBindSocket(this); - } - } - } - else{ - this->focusIn(); - } -} - -// 点击发送文件夹 -void ChatWidget::on_pb_senddir_clicked(){ - if(this->isIpExists() == false){ - this->sendType = ChatWidget::Dir; - - dirToSend = QFileDialog::getExistingDirectory(this, tr("pls choose dir to send"), ".", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); -// dirToSend = QFileDialog::getExistingDirectory(this, "请选择要发送的文件夹", ".", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - - if (dirToSend != "") { - bool rtn = this->findFile(dirToSend); - if(rtn){ - this->disableInput(); - if(this->isOnLine == true){ - emit sendDir(dirToSend); - - // 断线重连 - }else{ - this->slotTransferMsg(TRY_RECONN); - emit reBindSocket(this); - } - }else{ - this->ui->te_chatlog->append("" + tr("pls do not send empty dir") + ""); - // this->ui->te_chatlog->append("" + "请勿发送空文件夹" + ""); - } - } - } - else{ - this->focusIn(); - } -} - -// 递归判断文件夹里是否有文件 -bool ChatWidget::findFile(QString path){ - QDir dir(path); - dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - dir.setSorting(QDir::DirsFirst); - QFileInfoList list = dir.entryInfoList(); - - if(list.size() == 0){ - return false; - } - - int i=0; - do{ - QFileInfo fileInfo = list.at(i); - if(fileInfo.fileName()=="." | fileInfo.fileName()==".."){ - i++; - continue; - } - bool bisDir=fileInfo.isDir(); - if(bisDir){ - return findFile(fileInfo.filePath()); - }else{ - return true; - } - i++; - - }while(istopTransfer(true); - - QDateTime time = QDateTime::currentDateTime(); - QString alog = ""; - alog += tr("Me"); -// alog += "我"; - alog += " ("; - alog += time.toString("hh:mm:ss"); - alog += ")"; - this->ui->te_chatlog->append(alog); - this->ui->te_chatlog->append(tr("transmission canceled")); -// this->ui->te_chatlog->append("文件传输已取消"); - - this->enableInput(); - this->ui->lb_alert->setText(""); - this->ui->w_alert->hide(); - - this->sendType = ChatWidget::Idle; -} - -// 槽 当前连接是否为主动 -/* -* Parameters: -* isinitiative: is initiative -* Return : -*/ -void ChatWidget::getIsInitiativeConn(bool isInitiative){ - // 是主动则再次发起连接 - if(isInitiative == true){ - emit reBindSocket(this); - } -} - -// 键盘F1响应用户手册 -void ChatWidget::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - - case Qt::Key_F1: - if (!mDaemonIpcDbus->daemonIsNotRunning()){ - //增加标题栏帮助菜单、F1快捷键打开用户手册 - mDaemonIpcDbus->showGuide("kylin-ipmsg"); - } - break; - - default: - break; - } -} - -/* -* Summary: btn titleicon clicked -* Return : -*/ -void ChatWidget::on_pb_titleicon_clicked(){ - // 聊天窗关闭时,恢复原样 - // 如果是好友界面,则需要在下一次打开时显示修改备注按钮 - if (!(this->ui->pb_checkname->isHidden())) { - this->ui->pb_addname->show(); - } - - this->ui->le_nickname->clear(); - this->ui->le_nickname->hide(); - this->ui->pb_checkname->hide(); - this->ui->lb_name->show(); - this->ui->le_ip->clear(); - this->ui->w_alert->hide(); - - this->close(); - //this->hide(); -} - -/* -* Summary: open a url -* Parameters: -* url: http url -* Return : -*/ -void ChatWidget::openUrl(QUrl url){ - QDesktopServices::openUrl(QUrl::fromLocalFile(url.toString())); -} - -// 任务栏图标闪烁 -void ChatWidget::msgAlert(){ - if(this->timeFlag % 2 == 0){ - this->setWindowIcon(this->iconBlank); - }else{ - this->setWindowIcon(this->iconDukto); - } - this->timeFlag ++; -} - -// 注释后使用主题拖动 -// 窗口拖拽移动 -// void ChatWidget::mousePressEvent(QMouseEvent *event){ -// mMoveing = true; -// mMovePosition = event->globalPos() - pos(); -// } -// void ChatWidget::mouseMoveEvent(QMouseEvent *event){ -// if (mMoveing && (event->buttons() && Qt::LeftButton) -// && (event->globalPos()-mMovePosition).manhattanLength() > QApplication::startDragDistance()) -// { -// move(event->globalPos()-mMovePosition); -// mMovePosition = event->globalPos() - pos(); -// } -// } -// void ChatWidget::mouseReleaseEvent(QMouseEvent *){ -// mMoveing = false; -// } - -// 设置是否在线 -void ChatWidget::setOnLine(bool isOnLine){ - qDebug() << "setOnLine " << isOnLine; - this->isOnLine = isOnLine; -} - -// 后台消息处理 -void ChatWidget::slotTransferMsg(int code){ - if(code == CONN_SUCCESS){ - this->isOnLine = true; - this->ui->lb_alert->setText(""); - this->ui->w_alert->hide(); - - if(this->sendType == ChatWidget::Text){ - emit sendMsg(textToSend); - }else if(this->sendType == ChatWidget::Files){ - emit sendFiles(fileToSend); - }else if(this->sendType == ChatWidget::Dir){ - emit sendDir(dirToSend); - }else{ - } - } - if(code == CONN_TIMEOUT){ - this->ui->lb_alert->setText(tr("conn failed, try again later")); -// this->ui->lb_alert->setText("连接失败,请确认好友在线,稍后再试"); - this->ui->w_alert->show(); - this->enableInput(); - } - if(code == DISCONN){ - } - if(code == TRANSFERERR){ - this->ui->lb_alert->setText(tr("transmission error")); -// this->ui->lb_alert->setText("数据传输错误"); - this->ui->w_alert->show(); - } - if(code == TRY_RECONN){ - this->ui->lb_alert->setText(tr("connecting...")); -// this->ui->lb_alert->setText("正在尝试连接"); - this->ui->w_alert->show(); - } - if(code == SKIPFILE){ -// this->ui->lb_alert->setText("跳过了若干无权限的文件或符号链接"); -// this->ui->w_alert->show(); - } -} - -// 点击修改备注 -// 隐藏修改备注按钮,显示备注文本框和确认修改按钮 -void ChatWidget::on_pb_addname_clicked() -{ - this->ui->pb_addname->hide(); - this->ui->lb_name->hide(); - this->ui->le_nickname->show(); - this->ui->pb_checkname->show(); - this->ui->le_nickname->setFocus(); -} - - -// 确认修改按钮 -// 获取备注文本框的内容,隐藏文本框和确认修改按钮,显示备注名和修改备注按钮 - -void ChatWidget::on_pb_checkname_clicked() -{ - this->ip = this->dbuddy->ip(); - - QString nickname = this->ui->le_nickname->text().trimmed(); - QString mac = this->ip.split(" ")[1]; - - if (nickname != "") { - mSettings->saveNickname(mac, nickname); - for (int i = 0; i < this->buddies->keys().size(); i ++){ - QStandardItem *item = this->buddies->value(this->buddies->keys().at(i)); - if(mac.trimmed() == item->data(BuddyListItemModel::Mac).toString().trimmed()){ - item->setData(nickname, BuddyListItemModel::Username); - this->ui->lb_name->setText(nickname); -// qDebug() << "修改备注名" << nickname; - } - } - } - - this->ui->le_nickname->clear(); - this->ui->le_nickname->hide(); - this->ui->pb_checkname->hide(); - this->ui->lb_name->show(); - this->ui->pb_addname->show(); -} - diff --git a/chatwidget.h b/chatwidget.h deleted file mode 100644 index 1d6e812..0000000 --- a/chatwidget.h +++ /dev/null @@ -1,162 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef CHATWIDGET_H -#define CHATWIDGET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "buddylistitemmodel.h" -#include "destinationbuddy.h" -#include "settings.h" -#include "theme.h" -#include "ipaddressitemmodel.h" -#include "daemonipcdbus.h" - -#define MAXINPUTLEN 800 - -class Settings; - -namespace Ui { -class ChatWidget; -} - -class ChatWidget : public QDialog -{ - Q_OBJECT - -public: - explicit ChatWidget(QDialog *parent = 0); - ~ChatWidget(); - - void firstStyle(); - void showme(); - void disableInput(); - void focusOut(); - void focusIn(); - - inline Settings* settings() { return mSettings; } - - static const QString SPACE_STR; - static const QString SPACE_STR_HTML; - Theme * theme; - DestinationBuddy * dbuddy; - QString ip; - QString myIp; - QTimer *alertTimer; - QHash * buddies; - -public slots: - void addTextLog(QString text); - void addLogDirect(QString text); - void onSendCompleted(); - void enableInput(); - void startTransfer(bool isSend); - void updateTransferStatus(int percent, QString text, bool isSend); - void stopTransfer(bool isSend); - void slotTransferMsg(int code); - void setOnLine(bool isOnLine); - void recvCancel(); - void getIsInitiativeConn(bool); - - // 键盘F1响应用户手册 - void keyPressEvent(QKeyEvent *event); - -protected: - // 注释后使用主题拖动 - // void mousePressEvent(QMouseEvent *event); - // void mouseMoveEvent(QMouseEvent *event); - // void mouseReleaseEvent(QMouseEvent *event); - bool eventFilter(QObject *, QEvent *); - -signals: - void sendMsg(QString msg); - void sendFiles(QStringList files); - void sendDir(QString dirname); - void sendFileCanceled(); - void reSaveCw(QString ip); - void reBindSocket(ChatWidget *); - -private slots: - void on_pb_sendmsg_clicked(); - void on_pb_sendfile_clicked(); - void on_pb_senddir_clicked(); - void on_pb_titleicon_clicked(); - - void leTextChanged(QString); - void teTextChanged(); - void openUrl(QUrl url); - void msgAlert(); - - void on_pb_w_cancel_clicked(); - - // caoliang - void on_pb_addname_clicked(); - void on_pb_checkname_clicked(); - -private: - Ui::ChatWidget *ui; - - enum sendType_ { - Text, - Files, - Dir, - Idle - }; - int sendType; - - bool isOnLine; - - QString textToSend; - QString dirToSend; - QStringList fileToSend; - - QPoint mMovePosition; - bool mMoveing; - int timeFlag; - QIcon iconDukto; - QIcon iconBlank; - bool isFocus; - - bool isIpExists(); - bool findFile(QString path); - - Settings *mSettings; - IpAddressItemModel mIpAddresses; - DaemonIpcDbus *mDaemonIpcDbus; -}; - -#endif // CHATWIDGET_H diff --git a/chatwidget.ui b/chatwidget.ui deleted file mode 100644 index d14b34a..0000000 --- a/chatwidget.ui +++ /dev/null @@ -1,497 +0,0 @@ - - - ChatWidget - - - - 0 - 0 - 450 - 480 - - - - Kylin Ipmsg - - - - - 10 - 330 - 430 - 100 - - - - - - - 10 - 440 - 144 - 30 - - - - Send Text (Enter) - - - - - - 190 - 440 - 120 - 30 - - - - Send Files - - - - - - 320 - 440 - 120 - 30 - - - - Send Dir - - - - - - 60 - 5 - 255 - 40 - - - - - 24 - - - - Chat Widget - - - - - - 10 - 55 - 64 - 64 - - - - - - - - - - 90 - 60 - 161 - 25 - - - - - 13 - - - - - - - - - - 90 - 90 - 200 - 20 - - - - - - - - - - 10 - 55 - 64 - 64 - - - - - - - - - - 10 - 120 - 430 - 210 - - - - - - - 90 - 90 - 160 - 25 - - - - - 12 - - - - - - - 0 - 0 - 450 - 480 - - - - - - - - - - 2 - 308 - 446 - 170 - - - - - - 0 - 0 - 446 - 4 - - - - - - - - - - 0 - 166 - 446 - 4 - - - - - - - - - - 0 - 4 - 446 - 166 - - - - - - 17 - 55 - 412 - 45 - - - - 24 - - - - - - 16 - 5 - 200 - 40 - - - - - Noto Sans CJK SC - 11 - - - - Sending files... - - - - - - 309 - 116 - 120 - 30 - - - - Cancel - - - - - - 17 - 116 - 260 - 30 - - - - - Noto Sans CJK SC - 11 - - - - - - - - - - 17 - 55 - 0 - 45 - - - - - - - - - - - - 2 - 2 - 446 - 122 - - - - - - 0 - 118 - 446 - 4 - - - - - - - - - - 0 - 0 - 446 - 118 - - - - - - 17 - 55 - 412 - 45 - - - - 24 - - - - - - 56 - 5 - 180 - 40 - - - - - Noto Sans CJK SC - 11 - - - - Receiving files... - - - - - - 250 - 5 - 260 - 40 - - - - - Noto Sans CJK SC - 11 - - - - - - - - - - 17 - 55 - 0 - 45 - - - - - - - - - - - - 2 - 124 - 446 - 60 - - - - - - 16 - 10 - 414 - 40 - - - - - Noto Sans CJK SC - 11 - - - - - - - Qt::AlignCenter - - - - - - - 7 - 7 - 40 - 40 - - - - - - - - - - 270 - 60 - 150 - 25 - - - - - 0 - 0 - - - - Change nickname - - - - - - 270 - 60 - 150 - 25 - - - - - 0 - 0 - - - - Confirm change - - - - - - 90 - 60 - 160 - 25 - - - - 9 - - - - - - diff --git a/data/database/kylin-messages.db b/data/database/kylin-messages.db new file mode 100644 index 0000000..7a35035 Binary files /dev/null and b/data/database/kylin-messages.db differ diff --git a/data/guide/kylin-ipmsg/en_US/image/1.png b/data/guide/kylin-ipmsg/en_US/image/1.png deleted file mode 100644 index 7a5f5b7..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/1.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/10.png b/data/guide/kylin-ipmsg/en_US/image/10.png deleted file mode 100644 index 37855f1..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/10.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/2.png b/data/guide/kylin-ipmsg/en_US/image/2.png deleted file mode 100644 index 0f9215b..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/2.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/3.png b/data/guide/kylin-ipmsg/en_US/image/3.png deleted file mode 100644 index 655d521..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/3.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/4.png b/data/guide/kylin-ipmsg/en_US/image/4.png deleted file mode 100644 index 57ad813..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/4.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/5.png b/data/guide/kylin-ipmsg/en_US/image/5.png deleted file mode 100644 index c0ec244..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/5.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/6.png b/data/guide/kylin-ipmsg/en_US/image/6.png deleted file mode 100644 index 49e361f..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/6.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/7.png b/data/guide/kylin-ipmsg/en_US/image/7.png deleted file mode 100644 index cef97f9..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/7.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/8.png b/data/guide/kylin-ipmsg/en_US/image/8.png deleted file mode 100644 index 1cfef30..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/8.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/en_US/image/9.png b/data/guide/kylin-ipmsg/en_US/image/9.png deleted file mode 100644 index 4d8b4cb..0000000 Binary files a/data/guide/kylin-ipmsg/en_US/image/9.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/zh_CN/image/1.png b/data/guide/kylin-ipmsg/zh_CN/image/1.png deleted file mode 100644 index 3b3421b..0000000 Binary files a/data/guide/kylin-ipmsg/zh_CN/image/1.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/zh_CN/image/3.png b/data/guide/kylin-ipmsg/zh_CN/image/3.png deleted file mode 100644 index a1897b8..0000000 Binary files a/data/guide/kylin-ipmsg/zh_CN/image/3.png and /dev/null differ diff --git a/data/guide/kylin-ipmsg/zh_CN/image/4.png b/data/guide/kylin-ipmsg/zh_CN/image/4.png deleted file mode 100644 index 46deee0..0000000 Binary files a/data/guide/kylin-ipmsg/zh_CN/image/4.png and /dev/null differ diff --git a/data/guide/kylin-messages/en_US/image/1.png b/data/guide/kylin-messages/en_US/image/1.png new file mode 100644 index 0000000..ff48ce9 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/1.png differ diff --git a/data/guide/kylin-messages/en_US/image/2.png b/data/guide/kylin-messages/en_US/image/2.png new file mode 100644 index 0000000..439d561 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/2.png differ diff --git a/data/guide/kylin-messages/en_US/image/3.png b/data/guide/kylin-messages/en_US/image/3.png new file mode 100644 index 0000000..7aa6d57 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/3.png differ diff --git a/data/guide/kylin-messages/en_US/image/4.png b/data/guide/kylin-messages/en_US/image/4.png new file mode 100644 index 0000000..0abf186 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/4.png differ diff --git a/data/guide/kylin-messages/en_US/image/5.png b/data/guide/kylin-messages/en_US/image/5.png new file mode 100644 index 0000000..1330fb4 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/5.png differ diff --git a/data/guide/kylin-messages/en_US/image/6.png b/data/guide/kylin-messages/en_US/image/6.png new file mode 100644 index 0000000..efea0f9 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/6.png differ diff --git a/data/guide/kylin-messages/en_US/image/7.png b/data/guide/kylin-messages/en_US/image/7.png new file mode 100644 index 0000000..e8ef9a1 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/7.png differ diff --git a/data/guide/kylin-messages/en_US/image/8.png b/data/guide/kylin-messages/en_US/image/8.png new file mode 100644 index 0000000..dc19526 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/8.png differ diff --git a/data/guide/kylin-messages/en_US/image/9.png b/data/guide/kylin-messages/en_US/image/9.png new file mode 100644 index 0000000..ecad2c0 Binary files /dev/null and b/data/guide/kylin-messages/en_US/image/9.png differ diff --git a/data/guide/kylin-ipmsg/en_US/image/icon1.png b/data/guide/kylin-messages/en_US/image/icon1.png similarity index 100% rename from data/guide/kylin-ipmsg/en_US/image/icon1.png rename to data/guide/kylin-messages/en_US/image/icon1.png diff --git a/data/guide/kylin-ipmsg/en_US/image/icon2.png b/data/guide/kylin-messages/en_US/image/icon2.png similarity index 100% rename from data/guide/kylin-ipmsg/en_US/image/icon2.png rename to data/guide/kylin-messages/en_US/image/icon2.png diff --git a/data/guide/kylin-ipmsg/en_US/image/icon3.png b/data/guide/kylin-messages/en_US/image/icon3.png similarity index 100% rename from data/guide/kylin-ipmsg/en_US/image/icon3.png rename to data/guide/kylin-messages/en_US/image/icon3.png diff --git a/data/guide/kylin-ipmsg/en_US/index.md b/data/guide/kylin-messages/en_US/index.md similarity index 73% rename from data/guide/kylin-ipmsg/en_US/index.md rename to data/guide/kylin-messages/en_US/index.md index 0ed0c4b..11afcc6 100644 --- a/data/guide/kylin-ipmsg/en_US/index.md +++ b/data/guide/kylin-messages/en_US/index.md @@ -1,10 +1,10 @@ -# Kylin Ipmsg +# Messages ## Overview -Kylin Ipmsg is a cross platforms, efficient text/files transfer tool. And in order to avoid overwriting the original files, it will compare with the local file name when users transfer files. +Messages is a cross platforms, efficient text/files transfer tool. And in order to avoid overwriting the original files, it will compare with the local file name when users transfer files. All the functions are completed without server. -![Fig 1 Kylin Ipmsg](image/1.png) +![Fig 1 Messages](image/1.png)
## View Received Files @@ -57,6 +57,4 @@ It shows the communication recorders, and click one recorder to open the corresp
## About -Click "About" in the main interface to see the details of Kylin Ipmsg, as shown in Fig 10. - -![Fig 10 About](image/10.png) +Click "About" in the main interface to see the details of Messages. diff --git a/data/guide/kylin-ipmsg/kylin-ipmsg.png b/data/guide/kylin-messages/kylin-ipmsg.png similarity index 100% rename from data/guide/kylin-ipmsg/kylin-ipmsg.png rename to data/guide/kylin-messages/kylin-ipmsg.png diff --git a/data/guide/kylin-messages/zh_CN/image/1.png b/data/guide/kylin-messages/zh_CN/image/1.png new file mode 100644 index 0000000..90aacfe Binary files /dev/null and b/data/guide/kylin-messages/zh_CN/image/1.png differ diff --git a/data/guide/kylin-ipmsg/zh_CN/image/2.png b/data/guide/kylin-messages/zh_CN/image/2.png similarity index 100% rename from data/guide/kylin-ipmsg/zh_CN/image/2.png rename to data/guide/kylin-messages/zh_CN/image/2.png diff --git a/data/guide/kylin-messages/zh_CN/image/3.png b/data/guide/kylin-messages/zh_CN/image/3.png new file mode 100644 index 0000000..1d5482d Binary files /dev/null and b/data/guide/kylin-messages/zh_CN/image/3.png differ diff --git a/data/guide/kylin-messages/zh_CN/image/4.png b/data/guide/kylin-messages/zh_CN/image/4.png new file mode 100644 index 0000000..25049d6 Binary files /dev/null and b/data/guide/kylin-messages/zh_CN/image/4.png differ diff --git a/data/guide/kylin-ipmsg/zh_CN/image/5.png b/data/guide/kylin-messages/zh_CN/image/5.png similarity index 100% rename from data/guide/kylin-ipmsg/zh_CN/image/5.png rename to data/guide/kylin-messages/zh_CN/image/5.png diff --git a/data/guide/kylin-ipmsg/zh_CN/image/6.png b/data/guide/kylin-messages/zh_CN/image/6.png similarity index 100% rename from data/guide/kylin-ipmsg/zh_CN/image/6.png rename to data/guide/kylin-messages/zh_CN/image/6.png diff --git a/data/guide/kylin-ipmsg/zh_CN/image/icon1.png b/data/guide/kylin-messages/zh_CN/image/icon1.png similarity index 100% rename from data/guide/kylin-ipmsg/zh_CN/image/icon1.png rename to data/guide/kylin-messages/zh_CN/image/icon1.png diff --git a/data/guide/kylin-ipmsg/zh_CN/image/icon2.png b/data/guide/kylin-messages/zh_CN/image/icon2.png similarity index 100% rename from data/guide/kylin-ipmsg/zh_CN/image/icon2.png rename to data/guide/kylin-messages/zh_CN/image/icon2.png diff --git a/data/guide/kylin-ipmsg/zh_CN/image/icon3.png b/data/guide/kylin-messages/zh_CN/image/icon3.png similarity index 100% rename from data/guide/kylin-ipmsg/zh_CN/image/icon3.png rename to data/guide/kylin-messages/zh_CN/image/icon3.png diff --git a/data/guide/kylin-ipmsg/zh_CN/index.md b/data/guide/kylin-messages/zh_CN/index.md similarity index 71% rename from data/guide/kylin-ipmsg/zh_CN/index.md rename to data/guide/kylin-messages/zh_CN/index.md index aefb1dd..2507aa5 100644 --- a/data/guide/kylin-ipmsg/zh_CN/index.md +++ b/data/guide/kylin-messages/zh_CN/index.md @@ -1,10 +1,10 @@ -# 麒麟传书 +# 传书 ## 概 述 -麒麟传书是一个跨平台、高效的文字/文件传输工具。在用户传输文件时,会与本地文件名相互比较,避免覆盖原有的文件,损失重要信息。 +传书是一个跨平台、高效的文字/文件传输工具。在用户传输文件时,会与本地文件名相互比较,避免覆盖原有的文件,损失重要信息。 -麒麟传书无服务器设计,所有功能通过客户端完成。 +传书无服务器设计,所有功能通过客户端完成。 -![图 1 麒麟传书主界面](image/1.png) +![图 1 传书主界面](image/1.png)
### 查看已接收文件 @@ -37,4 +37,4 @@ ### 最近和关于 在主界面有三个标签页,点击“最近”,则切换到最近交谈消息管理页面。点击列表记录中的某条记录,则弹出与该用户通信的消息对话框,并显示之前的交谈记录。 -点击“关于”,可查看关于麒麟传输信息。 +点击“关于”,可查看传书关于信息。 diff --git a/kylin-ipmsg.desktop b/data/kylin-messages.desktop similarity index 84% rename from kylin-ipmsg.desktop rename to data/kylin-messages.desktop index d5ad104..f0bc6d7 100644 --- a/kylin-ipmsg.desktop +++ b/data/kylin-messages.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Encoding=UTF-8 -Name=Kylin Ipmsg -Name[zh_CN]=麒麟传书 +Name=Kylin Messages +Name[zh_CN]=新版传书 Name[zh_HK]=LAN 通訊工具 Name[zh_TW]=區域網路通訊工具 Name[bo_CN]=ཆི་ལིན་ཡིག་སྐྱལ། @@ -9,10 +9,10 @@ GenericName[bo_CN]=ཆི་ལིན་ཡིག་སྐྱལ། Comment=Beautiful LAN chat tool Comment[zh_CN]=麒麟局域网聊天工具,提供局域网聊天和文件传输功能,界面美观. Comment[bo_CN]=ཆི་ལིན་དྲ་ཆུང་དྲ་མོལ་ལག་ཆ། དྲ་ཆུང་དྲ་མོལ་དང་ཡིག་ཆ་བརྒྱུད་བསྒྲགས་ཀྱི་བྱེད་ནུས་འཆར་དངོས་མཛེས་བཟོ་སོགས་ཀྱི་བྱེད་ནུས་མཁོ་འདོན་བྱས་ཡོད། -Keywords=chat;talk;im;message;ipmsg; -Exec=/usr/bin/kylin-ipmsg +Keywords=chat;talk;im;message;messages; +Exec=/usr/bin/kylin-messages Icon=kylin-ipmsg StartupNotify=false Terminal=false Type=Application -Categories=InstantMessaging; +Categories=InstantMessaging; \ No newline at end of file diff --git a/data/schemas/org.ukui.log4qt.kylin-messages.gschema.xml b/data/schemas/org.ukui.log4qt.kylin-messages.gschema.xml new file mode 100644 index 0000000..1852c61 --- /dev/null +++ b/data/schemas/org.ukui.log4qt.kylin-messages.gschema.xml @@ -0,0 +1,39 @@ + + + + "true" + hook qt messages + Control if hook qt messages + + + "DEBUG,console,daily" + config rootLogger's level and appenders + config rootLogger's level and appenders:"level,appender" + + + ".yyyy-MM-dd" + daily log file pattern + set daily log file pattern format:one day + + + "%d{yyyy-MM-dd HH:mm:ss,zzz}(%-4r)[%t]|%-5p| - %m%n" + set log message's format + set log message's format + + + 3600 + set check log files delay time + set check log files delay time + + + 7 + set log files count + set log files count,unit s + + + 512 + set log files total size + set log files total size, unit M + + + diff --git a/data/translations/generate_translations_pm.sh b/data/translations/generate_translations_pm.sh new file mode 100644 index 0000000..a5e938e --- /dev/null +++ b/data/translations/generate_translations_pm.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +ts_file_list=(`ls translations/*.ts`) + +for ts in "${ts_file_list[@]}" +do + lrelease "${ts}" +done diff --git a/debian/changelog b/debian/changelog index 55ba272..a4d64ce 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,79 @@ +kylin-ipmsg (1.1.22kord5) v101; urgency=medium + + * 新增统一日志输出功能. + * 影响域:传书日志输出管理. + + -- caoliang Mon, 19 Apr 2021 20:20:16 +0800 + +kylin-ipmsg (1.1.22kord4) v101; urgency=medium + + * 修复禅道bug#49251 : 传书 - 打开窗体未置顶显示. + * 更新麒麟传书中英文应用名. + * 更新麒麟传书用户手册. + * 影响域:麒麟传书的中英文名显示,麒麟传书用户手册中的应用名文字显示及截图显示,最小化后启动应用拉起界面. + + -- caoliang Mon, 19 Apr 2021 10:28:27 +0800 + +kylin-ipmsg (1.1.22kord3) v101; urgency=medium + + * 修复禅道bug#47620 : 【主题框架】【麒麟传书】接收文件时崩溃. + + -- caoliang Tue, 13 Apr 2021 10:07:22 +0800 + +kylin-ipmsg (1.1.22kord2) v101; urgency=medium + + * 修复禅道bug#43504 : 【开始菜单】控制面板中切换图标主题为经典模式后,麒麟传书的图标不一致. + * 修复禅道bug#44435 : 【麒麟传书】麒麟传书,英文模式下,点击好友列表会话框没有显示在最上层. + + -- caoliang Sat, 27 Mar 2021 13:42:35 +0800 + +kylin-ipmsg (1.1.22kord1) v101; urgency=medium + + * 修复禅道bug#41391 : 【麒麟传书】麒麟传书最近中不显示传送文件消息. + * 修复禅道bug#41419 : 【麒麟传书】概率性传文件失败. + * 修复禅道bug#42312 : 【麒麟传书】传输文件,传输成功后,一直显示正在发送文件. + * 修复禅道bug#43810 : 【麒麟传书】麒麟传书,最近页面,接收到用户的的第一条消息不会显示用户信息. + * 修复禅道bug#43819 : 【麒麟传书】麒麟传书,传送文件过程中取消传送,取消失败,接收方的传送进度条也未消失. + * 修复禅道bug#43835 : 【麒麟传书】麒麟传书,发送方搜索IP后直接发送消息,无法停留在当前页面接收回复的消息. + * 修复禅道bug#44395 : 【麒麟传书】麒麟传书,发送消息时,用户无法接收到发送方的第一条消息. + * 修复禅道bug#44413 : 【麒麟传书】麒麟传书,停留在消息发送界面,修改备注名成功后,但是会话列表依然显示的是修改前的名字. + * 修复禅道bug#44014 : 【麒麟传书】麒麟传书任务栏预览窗口的名称修改. + * 应用版本号修改. + + -- caoliang Wed, 24 Mar 2021 16:57:51 +0800 + +kylin-ipmsg (1.1.21kord3) v101; urgency=medium + + * 修复禅道bug#42491 : 【麒麟传书】夜间模式下麒麟传书的窗口显示异常. + * 适配分数缩放. + + -- caoliang Mon, 15 Mar 2021 09:46:15 +0800 + +kylin-ipmsg (1.1.21kord2) v101; urgency=medium + + * 修复禅道bug#40482 : 【麒麟传书】打开后主界面会黑一下. + * 修复禅道bug#41910 : 【用户手册】【麒麟传书】只有麒麟传书图标,没有应用名,点进去显示undefined. + + -- caoliang Tue, 09 Mar 2021 14:01:08 +0800 + +kylin-ipmsg (1.1.21kord1) v101; urgency=medium + + * 在pro文件中对用户手册进行处理,兼容V10 + + -- caoliang Thu, 04 Mar 2021 17:07:17 +0800 + +kylin-ipmsg (1.1.20kord1~rc5) v101; urgency=medium + + * 【麒麟传书】#Bug39210 : 选择传输文件的模态窗口出现应用内主题颜色的边框. + + -- caoliang Wed, 24 Feb 2021 11:58:01 +0800 + +kylin-ipmsg (1.1.20kord1~rc4) v101; urgency=medium + + * 【麒麟传书】#Bug37940 : 使用IP时,显示两个IP地址且第二个显示不全. + + -- caoliang Wed, 03 Feb 2021 17:32:42 +0800 + kylin-ipmsg (1.1.20kord1~rc3) v101; urgency=medium * 【麒麟传书】#Bug36066 : 固定麒麟传书窗口大小,不响应全屏放大操作. diff --git a/debian/control b/debian/control index 7140d0c..aed6f19 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,8 @@ -Source: kylin-ipmsg +Source: kylin-messages Section: net Priority: optional -Maintainer: Kylin Development Team +Maintainer: caoliang + jishengjie Build-Depends: debhelper, qtbase5-dev (>= 5.6), qt5-qmake, @@ -10,19 +11,22 @@ Build-Depends: debhelper, qtchooser, qtscript5-dev, qttools5-dev-tools, - qtbase5-dev-tools + qtbase5-dev-tools, + pkgconf, + libgsettings-qt-dev, + libukui-log4qt-dev, + libkf5windowsystem-dev Standards-Version: 4.4.0 Homepage: https://github.com/ubuntukylin/kylin-ipmsg Vcs-Browser: https://github.com/ubuntukylin/kylin-ipmsg Vcs-Bzr: lp://dev/kylin-ipmsg -Package: kylin-ipmsg +Package: kylin-messages Architecture: any Depends: ${misc:Depends}, wmctrl (>= 1.07-6) -Conflicts: kylin-dukto -Description: Kylin Ipmsg - Kylin Ipmsg is a LAN chat tool with beautiful Gui. +Description: Messages + Messages is a LAN chat tool with beautiful Gui. . Features: * . diff --git a/debian/copyright b/debian/copyright index 5f7d31c..7d494b2 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,10 +1,11 @@ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: kylin-ipmsg -Upstream-Contact: Kylin Development Team +Upstream-Contact: caoliang + jishengjie Source: https://launchpad.dev/kylin-ipmsg Files: * -Copyright: 2016, National University of Defense Technology(NUDT) & Kylin Ltd +Copyright: Copyright (C) 2020, KylinSoft Co., Ltd. License: GPL-3 License: GPL-3 diff --git a/debian/rules b/debian/rules old mode 100755 new mode 100644 diff --git a/debian/source/local-options b/debian/source/local-options new file mode 100644 index 0000000..1f14633 --- /dev/null +++ b/debian/source/local-options @@ -0,0 +1,9 @@ +tar-ignore = build +tar-ignore = build-* +tar-ignore = .vscode +tar-ignore = .git +tar-ignore = .gitignore +tar-ignore = LICENSE +tar-ignore = .qm +tar-ignore = run +tar-ignore = README.md diff --git a/destinationbuddy.cpp b/destinationbuddy.cpp deleted file mode 100644 index a961742..0000000 --- a/destinationbuddy.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "destinationbuddy.h" -#include "buddylistitemmodel.h" - - -DestinationBuddy::DestinationBuddy(QObject *parent) : - QObject(parent) -{ -} - -/* -* Summary: fill friend from item -* Parameters: -* item: friend item -* Return : -*/ -void DestinationBuddy::fillFromItem(QStandardItem *item) -{ - mIp = item->data(BuddyListItemModel::Ip).toString(); - mPort = item->data(BuddyListItemModel::Port).toInt(); - mIptext = item->data(BuddyListItemModel::Iptext).toString(); - mUsername = item->data(BuddyListItemModel::Username).toString(); - mSystem = item->data(BuddyListItemModel::System).toString(); - mPlatform = item->data(BuddyListItemModel::Platform).toString(); - mGenericAvatar = item->data(BuddyListItemModel::GenericAvatar).toString(); - mAvatar = item->data(BuddyListItemModel::Avatar).toString(); - mOsLogo = item->data(BuddyListItemModel::OsLogo).toString(); - mShowBack = item->data(BuddyListItemModel::ShowBack).toString(); - emit ipChanged(); - emit portChanged(); - emit iptextChanged(); - emit usernameChanged(); - emit systemChanged(); - emit platformChanged(); - emit genericAvatarChanged(); - emit avatarChanged(); - emit osLogoChanged(); - emit showBackChanged(); -} - diff --git a/destinationbuddy.h b/destinationbuddy.h deleted file mode 100644 index c0a7c22..0000000 --- a/destinationbuddy.h +++ /dev/null @@ -1,80 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef DESTINATIONBUDDY_H -#define DESTINATIONBUDDY_H - -#include -#include - -class QStandardItem; - -class DestinationBuddy : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString ip READ ip NOTIFY ipChanged) - Q_PROPERTY(qint16 port READ port NOTIFY portChanged) - Q_PROPERTY(QString iptext READ iptext NOTIFY iptextChanged) - Q_PROPERTY(QString username READ username NOTIFY usernameChanged) - Q_PROPERTY(QString system READ system NOTIFY systemChanged) - Q_PROPERTY(QString platform READ platform NOTIFY platformChanged) - Q_PROPERTY(QString genericAvatar READ genericAvatar NOTIFY genericAvatarChanged) - Q_PROPERTY(QString avatar READ avatar NOTIFY avatarChanged) - Q_PROPERTY(QString osLogo READ osLogo NOTIFY osLogoChanged) - Q_PROPERTY(QString showBack READ showBack NOTIFY showBackChanged) - -public: - explicit DestinationBuddy(QObject *parent = 0); - inline QString ip() { return mIp; } - inline qint16 port() { return mPort; } - inline QString iptext() { return mIptext; } - inline QString username() { return mUsername; } - inline QString system() { return mSystem; } - inline QString platform() { return mPlatform; } - inline QString genericAvatar() { return mGenericAvatar; } - inline QString avatar() { return mAvatar; } - inline QString osLogo() { return mOsLogo; } - inline QString showBack() { return mShowBack; } - void fillFromItem(QStandardItem *item); - - QString mIp; - qint16 mPort; - QString mIptext; - QString mUsername; - QString mSystem; - QString mPlatform; - QString mGenericAvatar; - QString mAvatar; - QString mOsLogo; - QString mShowBack; - -signals: - void ipChanged(); - void portChanged(); - void iptextChanged(); - void usernameChanged(); - void systemChanged(); - void platformChanged(); - void genericAvatarChanged(); - void avatarChanged(); - void osLogoChanged(); - void showBackChanged(); -}; - -#endif // DESTINATIONBUDDY_H diff --git a/dukto.rc b/dukto.rc deleted file mode 100644 index 412ce4a..0000000 --- a/dukto.rc +++ /dev/null @@ -1,48 +0,0 @@ -IDI_ICON1 ICON DISCARDABLE "dukto.ico" - -#include - -#define VER_FILEVERSION 6,0,0,0 -#define VER_FILEVERSION_STR "6.0.0.0\0" - -#define VER_PRODUCTVERSION 6,0,0,0 -#define VER_PRODUCTVERSION_STR "6.0\0" - -#define VER_COMPANYNAME_STR "msec.it" -#define VER_FILEDESCRIPTION_STR "Dukto R6" -#define VER_INTERNALNAME_STR "Dukto R6" -#define VER_LEGALCOPYRIGHT_STR "Copyright 2013 Emanuele Colombo" -#define VER_LEGALTRADEMARKS1_STR "All Rights Reserved" -#define VER_LEGALTRADEMARKS2_STR VER_LEGALTRADEMARKS1_STR -#define VER_ORIGINALFILENAME_STR "dukto.exe" -#define VER_PRODUCTNAME_STR "Dukto R6" - -#define VER_COMPANYDOMAIN_STR "msec.it" - - -VS_VERSION_INFO VERSIONINFO -FILEVERSION VER_FILEVERSION -PRODUCTVERSION VER_PRODUCTVERSION -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - BEGIN - VALUE "CompanyName", VER_COMPANYNAME_STR - VALUE "FileDescription", VER_FILEDESCRIPTION_STR - VALUE "FileVersion", VER_FILEVERSION_STR - VALUE "InternalName", VER_INTERNALNAME_STR - VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR - VALUE "LegalTrademarks1", VER_LEGALTRADEMARKS1_STR - VALUE "LegalTrademarks2", VER_LEGALTRADEMARKS2_STR - VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR - VALUE "ProductName", VER_PRODUCTNAME_STR - VALUE "ProductVersion", VER_PRODUCTVERSION_STR - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END diff --git a/duktoprotocol.cpp b/duktoprotocol.cpp deleted file mode 100644 index 1213ec7..0000000 --- a/duktoprotocol.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "guibehind.h" -#include "platform.h" - - -DuktoProtocol::DuktoProtocol(GuiBehind *gb) - : mSocket(NULL), mTcpServer(NULL) -{ - this->gbehind = gb; - this->pSystemSignature = this->getSystemSignature(); -} - -DuktoProtocol::~DuktoProtocol() -{ - qDebug() << "~DuktoProtocol"; - if (mSocket) { -// delete mSocket; - mSocket->deleteLater(); - mSocket = NULL; - } - if (mTcpServer) { - mTcpServer->close(); -// delete mTcpServer; - mTcpServer->deleteLater(); - mTcpServer = NULL; - } - - qDebug() << "discardSockets"; - // 释放废弃的socket类 - for(int i = 0; i < this->discardSockets.size(); i ++){ - KSocket *t_ = discardSockets[i]; -// delete t_; - t_->deleteLater(); - t_ = NULL; - } -} - -/* -* Summary: init -* Return : -*/ -void DuktoProtocol::initialize() -{ - mSocket = new QUdpSocket(this); - mSocket->bind(QHostAddress::AnyIPv4, NETWORK_PORT, QUdpSocket::ReuseAddressHint); - connect(mSocket, SIGNAL(readyRead()), this, SLOT(newUdpData())); - - mTcpServer = new KTcpServer(); - qDebug() << "mTcpServer->listen" <listen(QHostAddress::AnyIPv4, NETWORK_PORT); - connect(mTcpServer, SIGNAL(newConn(qintptr)), this, SLOT(newIncomingConnection(qintptr))); -} - -// 生成本机标识 -QString DuktoProtocol::getSystemSignature() -{ - static QString signature = ""; - if (signature != "") return signature; - - signature = "kylin-ipmsg " + Platform::getSystemUsername() - + " " + Platform::getHostname() - + " " + this->getMac() - + " " + Platform::getPlatformName(); - return signature; -} - -// 获取本机MAC地址 -QString DuktoProtocol::getMac(){ -// foreach(QNetworkInterface ni, QNetworkInterface::allInterfaces()){ -// if(ni.name() != "lo"){ -// return ni.hardwareAddress(); -// break; -// } -// } - -// return "NOMAC"; - - // caoliang 获取正确的本机MAC地址 - // 获取所有网络接口列表 - QList nets = QNetworkInterface::allInterfaces(); - int netCnt = nets.count(); - QString strMacAddr = ""; - - for (int i = 0; i < netCnt; i++) { - // 如果此网络接口被激活并且正在运行并且不是回环地址,则就是我们需要找的Mac地址 - if(nets[i].flags().testFlag(QNetworkInterface::IsUp) && nets[i].flags().testFlag(QNetworkInterface::IsRunning) && !nets[i].flags().testFlag(QNetworkInterface::IsLoopBack)) - { - strMacAddr = nets[i].hardwareAddress(); - return strMacAddr; - break; - } - } - return "NOMAC"; -} - -// 上线广播 -void DuktoProtocol::sayHello(QHostAddress dest) -{ - QByteArray *packet = new QByteArray(); - - // 广播 - if (dest == QHostAddress::Broadcast){ - packet->append(UDP_BROADCAST); - packet->append(this->pSystemSignature); - this->sendToAllBroadcast(packet); - - // 单播 - }else{ - packet->append(UDP_UNICAST); - packet->append(this->pSystemSignature); - this->mSocket->writeDatagram(packet->data(), packet->length(), dest, NETWORK_PORT); - } - - delete packet; - packet = NULL; -} - -// 下线广播 -void DuktoProtocol::sayGoodbye() -{ - QByteArray *packet = new QByteArray(); - packet->append(UDP_GOODBYE); - packet->append(this->pSystemSignature); - sendToAllBroadcast(packet); - - delete packet; - packet = NULL; -} - -// 广播发送 -/* -* Parameters: -* packet: broadcast msg packet -* Return : -*/ -void DuktoProtocol::sendToAllBroadcast(QByteArray *packet) -{ - // 所有网络接口 - QList ifaces = QNetworkInterface::allInterfaces(); - - for (int i = 0; i < ifaces.size(); i++) - { - // 每一个网络接口的所有IP地址 - QList addrs = ifaces[i].addressEntries(); - - for (int j = 0; j < addrs.size(); j++){ - // 如果该网络接口的该IP地址是IPV4,并且有广播地址,则发送广播 - if ((addrs[j].ip().protocol() == QAbstractSocket::IPv4Protocol) && (addrs[j].broadcast().toString() != "")) - { - mSocket->writeDatagram(packet->data(), packet->length(), addrs[j].broadcast(), NETWORK_PORT); - mSocket->flush(); - } - } - } -} - -// 收到广播 -void DuktoProtocol::newUdpData() -{ - qDebug() << "收到广播newUdpData"; - while (mSocket->hasPendingDatagrams()) { - QByteArray datagram; - const int maxLength = 65536; - datagram.resize(maxLength); - QHostAddress sender; - int size = mSocket->readDatagram(datagram.data(), datagram.size(), &sender); - datagram.resize(size); - handleMessage(datagram, sender); - } -} - -// 处理广播消息 -/* -* Parameters: -* data: msg data -* sender: msg sender -* Return : -*/ -void DuktoProtocol::handleMessage(QByteArray &data, QHostAddress &sender) -{ - char msgtype = data.at(0); - data.remove(0, 1); - QString dataStr = QString::fromUtf8(data); - switch(msgtype) - { - case UDP_BROADCAST: - case UDP_UNICAST: - - if(dataStr != this->pSystemSignature && dataStr.startsWith("kylin-ipmsg ") == true){ - mPeers[dataStr] = Peer(sender, dataStr, NETWORK_PORT); - - /*print Qhash*/ - QHash::iterator it_begin = mPeers.begin(); - QHash::iterator it_end = mPeers.end(); - while (it_begin != it_end) { - qDebug() << "QHash" << it_begin.key() << it_begin.value().address; - it_begin++; - } - - if(msgtype == UDP_BROADCAST){ - sayHello(sender); - } - - emit peerListAdded(mPeers[dataStr]); - } - break; - - case UDP_GOODBYE: - emit peerListRemoved(mPeers[dataStr]); - mPeers.remove(sender.toString()); - break; - } -} - -// 主动连接 -/* -* Parameters: -* targetip: target ip address -* remoteid: remote id -* cw: chat widget object -* Return : -*/ -void DuktoProtocol::newOutgoingConnection(QString targetIP, QString remoteID, ChatWidget *cw){ - qDebug() << "客户端主动连接函数 : newOutgoingConnection"; - qDebug() << "客户端主动链接函数参数 : " << targetIP << remoteID; - QThread *qthread = new QThread(); - KSocket *ks = new KSocket(targetIP, this->pSystemSignature, remoteID); - ks->moveToThread(qthread); - - connect(cw, SIGNAL(sendMsg(QString)), ks, SLOT(sendText(QString))); - connect(ks, SIGNAL(sendTextComplete()), cw, SLOT(onSendCompleted())); - connect(ks , SIGNAL(sendTextComplete_add_recentlist(QString , QString)) , this->gbehind , SLOT(sendTextComplete_add_recentlist(QString , QString))); - connect(ks, SIGNAL(receiveTextComplete(QString, QString)), this->gbehind, SLOT(receiveTextComplete(QString, QString))); - - connect(cw, SIGNAL(sendFiles(QStringList)), ks, SLOT(sendFiles(QStringList))); - connect(cw, SIGNAL(sendDir(QString)), ks, SLOT(sendDir(QString))); - connect(cw, SIGNAL(sendFileCanceled()), ks, SLOT(sendCancel())); - connect(ks, SIGNAL(startTransfer(bool)), cw, SLOT(startTransfer(bool))); - connect(ks, SIGNAL(updateTransferStatus(int, QString, bool)), cw, SLOT(updateTransferStatus(int, QString, bool))); - connect(ks, SIGNAL(sendFileComplete()), cw, SLOT(onSendCompleted())); - connect(ks, SIGNAL(receiveFileComplete(QStringList*, qint64, QString, QString)), this->gbehind, SLOT(receiveFileComplete(QStringList*, qint64, QString, QString))); - connect(ks, SIGNAL(receiveFileCancelled()), cw, SLOT(recvCancel())); - connect(ks, SIGNAL(isInitiativeConn(bool)), cw, SLOT(getIsInitiativeConn(bool))); - connect(ks, SIGNAL(addUpBuddy(QString , QString , QString , QString , QString)), this, SLOT(addUpBuddy(QString , QString , QString , QString , QString))); - - connect(ks, SIGNAL(transferMsgSignal(int)), cw, SLOT(slotTransferMsg(int))); - - connect(qthread, SIGNAL(started()), ks, SLOT(imStart())); - - connect(ks, SIGNAL(finished()), qthread, SLOT(quit())); - connect(qthread, SIGNAL(finished()), qthread, SLOT(deleteLater())); - connect(ks, SIGNAL(finished()), ks, SLOT(deleteLater())); - connect(ks, SIGNAL(finished(QString)), this, SLOT(updateSockets(QString))); - connect(ks, SIGNAL(finished(bool)), cw, SLOT(setOnLine(bool))); - - this->gbehind->sockets.insert(remoteID, ks); - qthread->start(); -} - -// 被动连接 -/* -* Parameters: -* socketdescriptor: incoming connection socket -* Return : -*/ -void DuktoProtocol::newIncomingConnection(qintptr socketDescriptor) -{ - qDebug() << "服务端被动连接newIncomingConnection"; - qDebug() << "socketDescriptor = " << socketDescriptor; - QThread *qthread = new QThread(); - KSocket *ks = new KSocket(socketDescriptor , this->pSystemSignature); - ks->moveToThread(qthread); - - connect(ks, SIGNAL(updateRemoteID(QString, QString , QString , QString , QString ,KSocket*)), this, SLOT(updateRemoteID(QString, QString , QString , QString , QString , KSocket*))); - - connect(ks, SIGNAL(receiveTextComplete(QString, QString)), this->gbehind, SLOT(receiveTextComplete(QString, QString))); - - connect(ks, SIGNAL(receiveFileComplete(QStringList*, qint64, QString, QString)), this->gbehind, SLOT(receiveFileComplete(QStringList*, qint64, QString, QString))); - - connect(qthread, SIGNAL(started()), ks, SLOT(imReady())); - connect(qthread, SIGNAL(finished()), qthread, SLOT(deleteLater())); - connect(ks, SIGNAL(finished()), ks, SLOT(deleteLater())); - connect(ks, SIGNAL(finished(QString)), this, SLOT(updateSockets(QString))); - - qthread->start(); -} - -// 被动连接后,收到对方remoteID,更新信息 -/* -* Parameters: -* premoteid: remote id in -* ks: kylin socket object -* Return : -*/ -void DuktoProtocol::updateRemoteID(QString ip, QString user_name , QString system , QString pRemoteID , QString Platform , KSocket* ks){ - // 添加下级网络好友,如果已有该好友,addBuddy()中不会重复添加 - qDebug() << "服务端更新信息:" << "ip :" << ip << "\n" << "user_name :" << user_name << "\n" << "system :" << system << "\n" << "mac :" << pRemoteID << "\n" << "Platform :" << Platform << "\n"; - - this->gbehind->mBuddiesList.addBuddy(ip, NETWORK_PORT, user_name , system , pRemoteID, Platform , QUrl("")); - - // 保存到map中供界面使用 - if(this->gbehind->sockets.contains(pRemoteID) == false){ - this->gbehind->sockets.insert(pRemoteID, ks); - }else{ - KSocket *ks_ = this->gbehind->sockets.value(pRemoteID); - if((unsigned long)ks != (unsigned long)ks_){ - this->discardSockets.append(ks_); - this->gbehind->sockets.remove(pRemoteID); - this->gbehind->sockets.insert(pRemoteID, ks); - } - } - - // 被动连接,绑定信号 - ChatWidget *cw = NULL; - foreach (ChatWidget *cw_, this->gbehind->cws) { - QString oneMac = cw_->dbuddy->ip().split(" ")[1]; - if(oneMac == pRemoteID){ - cw = cw_; - } - } - if(cw == NULL){ - cw = this->gbehind->createCW(pRemoteID); - } - cw->setOnLine(true); - - connect(cw, SIGNAL(sendMsg(QString)), ks, SLOT(sendText(QString))); - connect(ks, SIGNAL(sendTextComplete()), cw, SLOT(onSendCompleted())); - - connect(cw, SIGNAL(sendFiles(QStringList)), ks, SLOT(sendFiles(QStringList))); - connect(cw, SIGNAL(sendDir(QString)), ks, SLOT(sendDir(QString))); - connect(cw, SIGNAL(sendFileCanceled()), ks, SLOT(sendCancel())); - connect(ks, SIGNAL(startTransfer(bool)), cw, SLOT(startTransfer(bool))); - connect(ks, SIGNAL(updateTransferStatus(int, QString, bool)), cw, SLOT(updateTransferStatus(int, QString, bool))); - connect(ks, SIGNAL(sendFileComplete()), cw, SLOT(onSendCompleted())); - connect(ks, SIGNAL(receiveFileCancelled()), cw, SLOT(recvCancel())); - connect(ks, SIGNAL(isInitiativeConn(bool)), cw, SLOT(getIsInitiativeConn(bool))); - - connect(ks, SIGNAL(transferMsgSignal(int)), cw, SLOT(slotTransferMsg(int))); - - connect(ks, SIGNAL(finished(bool)), cw, SLOT(setOnLine(bool))); - - qDebug()<<"活跃sockets: "<gbehind->sockets.size()<<" 废弃sockets: "<discardSockets.size(); -} - -// 清除sockets中的指定socket -/* -* Parameters: -* premoteid: remote id -* Return : -*/ -void DuktoProtocol::updateSockets(QString pRemoteID){ - qDebug() << "DuktoProtocol::updateSockets"; - if(this->gbehind->sockets.contains(pRemoteID) == true){ - KSocket *ks_ = this->gbehind->sockets.value(pRemoteID); - qDebug() << "KSocket *ks_"; - this->discardSockets.append(ks_); - qDebug() << "discardSockets.append" << pRemoteID ; - this->gbehind->sockets.remove(pRemoteID); - qDebug() << "sockets.remove(pRemoteID)"; - } -} - -// 绑定聊天窗口和socket -/* -* Parameters: -* cw: chat widget object -* Return : -*/ -void DuktoProtocol::connectSocketAndChatWidget(ChatWidget *cw){ - qDebug() << "active link tcp , create chatwidget and socket contact"; - - QString ip = cw->dbuddy->ip().split(" ")[0]; - QString remoteID = cw->dbuddy->ip().split(" ")[1]; - - // 主动连接,为聊天窗口建立新的socket连接 - if(this->gbehind->sockets.contains(remoteID) == false){ - this->newOutgoingConnection(ip, remoteID, cw); - - }else{ - KSocket *ks_ = this->gbehind->sockets.value(remoteID); - // 已有连接已断开,但还没来得及销毁。销毁并建立主动连接 - if(ks_->isConnected == false){ - qDebug() << "connectSocketAndChatWidget"; - this->updateSockets(remoteID); - this->newOutgoingConnection(ip, remoteID, cw); - } - } -} - -// 添加上层网络好友 -/* -* Parameters: -* ip: friend ip address -* mac: friend mac address -* Return : -*/ -void DuktoProtocol::addUpBuddy(QString ip, QString user_name , QString system , QString mac , QString Platform){ - // 如果已有该好友,addBuddy()中不会重复添加 - this->gbehind->mBuddiesList.addBuddy(ip, NETWORK_PORT, user_name , system , mac, Platform , QUrl("")); -} diff --git a/duktoprotocol.h b/duktoprotocol.h deleted file mode 100644 index 43d3ed3..0000000 --- a/duktoprotocol.h +++ /dev/null @@ -1,24 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef DUKTOPROTOCOL_H -#define DUKTOPROTOCOL_H - - -#endif // DUKTOPROTOCOL_H diff --git a/duktowindow.cpp b/duktowindow.cpp deleted file mode 100644 index f1c48ee..0000000 --- a/duktowindow.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "duktowindow.h" -#include "guibehind.h" -#include "platform.h" -#include "settings.h" - -DuktoWindow::DuktoWindow(QWindow *parent) : - QmlApplicationViewer(parent), mGuiBehind(NULL){ - - this->setTitle(tr("Kylin Ipmsg")); -// this->setIcon(QIcon("/usr/share/pixmaps/kylin-ipmsg.png")); - this->setIcon(QIcon::fromTheme("kylin-ipmsg")); - - // 响应用户手册 - mDaemonIpcDbus = new DaemonIpcDbus(); - -// this->setWindowTitle(tr("Kylin Ipmsg")); -// setWindowTitle("麒麟传书"); -// setWindowIcon(QIcon("/usr/share/pixmaps/kylin-ipmsg.png")); - QString iconPath = "/usr/share/icons/ukui-icon-theme-default/64x64/apps/kylin-ipmsg.png"; - QFileInfo fi(iconPath); - if (!fi.exists()) { - iconPath = "/usr/share/icons/kylin-icon-theme/64x64/apps/kylin-ipmsg.png"; - fi.setFile(iconPath); - if (!fi.exists()) { - iconPath = "/usr/share/pixmaps/kylin-ipmsg.png"; - } - } - -// this->setIcon(QIcon(iconPath)); - this->setIcon(QIcon::fromTheme("kylin-ipmsg")); - - setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait); - - // 固定窗口大小 - int fixedWidth = 330; - int fixedHeight = 600; - setMaximumWidth(fixedWidth); - setMinimumWidth(fixedWidth); - setMaximumHeight(fixedHeight); - setMinimumHeight(fixedHeight); - - // 固定初始窗口位置到屏幕中央 - QRect availableGeometry = qApp->primaryScreen()->availableGeometry(); - this->setGeometry((availableGeometry.width() - fixedWidth)/2, - (availableGeometry.height() - fixedHeight)/2, - fixedWidth, fixedHeight); -} - -/* -* Summary: set gui reference -* Parameters: -* ref: gui behind object -* Return : -*/ -void DuktoWindow::setGuiBehindReference(GuiBehind* ref){ - mGuiBehind = ref; -} - -/* -* Summary: close event -* Parameters: -* qt close event -* Return : -*/ -void DuktoWindow::closeEvent(QCloseEvent *event){ -// mGuiBehind->settings()->saveWindowGeometry(saveGeometry()); - mGuiBehind->settings()->saveWindowGeometry(frameGeometry()); - mGuiBehind->close(); - - qDebug() << "exit(0)exit(0)exit(0)exit(0)exit(0)"; - event->accept(); - exit(0); -} - -void DuktoWindow::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - - case Qt::Key_F1: -// qDebug() << "DuktoWindow keyPressEvent Key_F1" << mDaemonIpcDbus->daemonIsNotRunning(); - - if (!mDaemonIpcDbus->daemonIsNotRunning()){ - //增加标题栏帮助菜单、F1快捷键打开用户手册 - mDaemonIpcDbus->showGuide("kylin-ipmsg"); - } - break; - - default: - break; - } -} diff --git a/duktowindow.h b/duktowindow.h deleted file mode 100644 index 8148d78..0000000 --- a/duktowindow.h +++ /dev/null @@ -1,61 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef DUKTOWINDOW_H -#define DUKTOWINDOW_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "qmlapplicationviewer/qmlapplicationviewer.h" -#include "daemonipcdbus.h" - -class GuiBehind; - -class DuktoWindow : public QmlApplicationViewer -{ - Q_OBJECT - -public: - explicit DuktoWindow(QWindow *parent = 0); - void setGuiBehindReference(GuiBehind* ref); - -protected: - void closeEvent(QCloseEvent *event); - -signals: - -public slots: - - void keyPressEvent(QKeyEvent *event); - -private: - GuiBehind *mGuiBehind; - DaemonIpcDbus *mDaemonIpcDbus; -}; - -#endif // DUKTOWINDOW_H diff --git a/guibehind.cpp b/guibehind.cpp deleted file mode 100644 index 0a5fd11..0000000 --- a/guibehind.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "guibehind.h" -#include "settings.h" -#include "miniwebserver.h" -#include "duktowindow.h" -#include "platform.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -GuiBehind::GuiBehind(DuktoWindow* view) : - QObject(NULL), mView(view), mPeriodicHelloTimer(NULL), - mMiniWebServer(NULL), mSettings(NULL) -{ - // 通信管理中心 - mDuktoProtocol = new DuktoProtocol(this); - // 头像web服务器 - mMiniWebServer = new MiniWebServer(); - // 设置中心 - mSettings = new Settings(this); - // 添加 "本机" 到好友列表strip - mBuddiesList.addMeElement(tr(" (You)")); - // 添加 "使用IP地址" 到好友列表 - mBuddiesList.addIpElement(tr("Use IP Address"), tr("Contact with parent network")); - // 响应用户手册 - mDaemonIpcDbus = new DaemonIpcDbus(); - - mView->setGuiBehindReference(this); - QDir::setCurrent(mSettings->currentPath()); - mTheme.setThemeColor(mSettings->themeColor()); - - // qml属性填充 - view->rootContext()->setContextProperty("buddiesListData", &mBuddiesList); - view->rootContext()->setContextProperty("recentListData", &mRecentList); - view->rootContext()->setContextProperty("ipAddressesData", &mIpAddresses); - view->rootContext()->setContextProperty("guiBehind", this); - view->rootContext()->setContextProperty("theme", &mTheme); - - connect(mDuktoProtocol, SIGNAL(peerListAdded(Peer)), this, SLOT(peerListAdded(Peer))); - connect(mDuktoProtocol, SIGNAL(peerListRemoved(Peer)), this, SLOT(peerListRemoved(Peer))); - - // 上线发广播 - /*init udp server and tcp server*/ - mDuktoProtocol->initialize(); - mDuktoProtocol->sayHello(QHostAddress::Broadcast); - - // 定时发广播 - mPeriodicHelloTimer = new QTimer(this); - connect(mPeriodicHelloTimer, SIGNAL(timeout()), this, SLOT(periodicHello())); - mPeriodicHelloTimer->start(60000); - - // 新消息闪烁提示相关 - this->alertTimer = new QTimer(this); - this->alertTimer->setInterval(300); - this->connect(this->alertTimer, SIGNAL(timeout()), this, SLOT(msgAlert())); - - this->iconDukto = QIcon::fromTheme("kylin-ipmsg"); - QString themeName = this->iconDukto.themeName(); - - QString iconPath = mSettings->iconPath(); - QFileInfo fi(iconPath); - - // icon图标路径 - iconPath = "/usr/share/icons/"+ themeName + "/64x64/apps/kylin-ipmsg.png"; - fi.setFile(iconPath); - if (fi.exists()) { - mSettings->saveIconPath(iconPath); - } - else { - // 保险措施 - iconPath = "/usr/share/pixmaps/kylin-ipmsg.png"; - mSettings->saveIconPath(iconPath); - } - - // qml访问本地图片需使用绝对路径 - this->setIconPath(iconPath); - - // 加载 GUI - view->setSource(QUrl("qrc:/qml/dukto/Dukto.qml")); - //TODO: check QtQuick 2 restoreGeometry -// view->restoreGeometry(mSettings->windowGeometry()); -// view->setGeometry(mSettings->windowGeometry()); - - this->iconBlank = QIcon(":/qml/dukto/Blank.png"); - - this->cwx = -1; - this->cwy = -1; - this->timeFlag = 0; -} - -GuiBehind::~GuiBehind(){ - mDuktoProtocol->sayGoodbye(); - - if (mMiniWebServer) mMiniWebServer->deleteLater(); - if (mPeriodicHelloTimer) mPeriodicHelloTimer->deleteLater(); - if (mView) mView->deleteLater(); - if (mSettings) mSettings->deleteLater(); -} - -// 在列表中添加新好友 -void GuiBehind::peerListAdded(Peer peer){ - mBuddiesList.addBuddy(peer); -} - -// 收到goodbye消息,在列表中删除对应好友 -void GuiBehind::peerListRemoved(Peer peer){ - mBuddiesList.removeBuddy(peer.mac); -} - -/*send text finish add receive list*/ -void GuiBehind::sendTextComplete_add_recentlist(QString text , QString mac) -{ - QStandardItem *buddy = NULL; - buddy = mBuddiesList.buddyByMac(mac); - - qDebug() << "sendTextComplete_add_recentlist fun call args ->" << "mac : " << mac << "text : " << text << "buddy list point : " << buddy; - - QString userName; - QString ip_mac; - userName.clear(); - ip_mac.clear(); - if (buddy != NULL) { - userName = buddy->data(BuddyListItemModel::Username).toString(); - ip_mac = buddy->data(BuddyListItemModel::Ip).toString(); - - qDebug() << "username :" << userName << "ip_mac :" << ip_mac; - - /*delete recent item and again add*/ - this->removeRecentItem(mac); - mRecentList.addRecent("Text snippet", text, "text", userName , 0 , ip_mac); - } - - return; -} - -// 一次文件接收完成 -/* -* Parameters: -* files: receive files -* totalsize: total size -* dir: dir -* mac: mac address -* Return : -*/ -void GuiBehind::receiveFileComplete(QStringList *files, qint64 totalSize, QString dir, QString mac){ - QDir d("."); - QStandardItem *buddy = mBuddiesList.buddyByMac(mac); - QString userName = buddy->data(BuddyListItemModel::Username).toString(); - - // 时间头 - QDateTime time = QDateTime::currentDateTime(); - QString tHead = ""; - tHead += userName; - tHead += " ("; - tHead += time.toString("hh:mm:ss"); - tHead += ")"; - - QString msg = ""; - QStringList tmpList; - // 收到的是文件 - if (dir == ""){ -// msg = "收到文件 "; - msg = ""+tr("Received file" ); - if(files->size() == 1){ - msg += "'"; - msg += files->at(0); -// msg += "' 大小 ("; - msg += "' "+tr("size")+" ("; - msg += this->sizeHuman(totalSize); - msg += ")
"; -// msg += "打开"; - msg += ""+tr("Open")+""; -// msg += "  打开目录"; - msg += "  "+tr("Open directory")+""; - }else{ - msg += QString::number(files->size()); -// msg += " 个"; - msg += " "+tr("files"); -// msg += " 共计大小 ("; - msg += " "+tr("Total size")+" ("; - msg += this->sizeHuman(totalSize); - msg += ")
"; - for(int i = 0; i < files->size(); i ++){ - msg += "'"; - msg += files->at(i); - msg += "' "; - } - msg += "

"+tr("Open directory")+""; - } - - // 收到的是文件夹 - }else{ -// msg = "收到文件夹 '" + dir + "' 共计大小 ("; - msg = ""+tr("Received folder")+" '" + dir + "' "+tr("Total size")+" ("; - msg += this->sizeHuman(totalSize); - msg += ")
"; - msg += ""+tr("Open directory")+""; - } - - // 已有该对话框,直接append - if(this->cws.contains(mac)){ - ChatWidget *cw = this->cws.value(mac); - cw->addLogDirect(tHead); - cw->addLogDirect(msg); - cw->stopTransfer(false); - - // 没有该对话框,先保存在tmpMsgs中 - }else{ - // 已有该tmpMsg,取出继续使用 - if(this->tmpMsgs.contains(mac)){ - tmpList = this->tmpMsgs.value(mac); - } - tmpList.append(tHead); - tmpList.append(msg); - this->tmpMsgs.insert(mac, tmpList); - } - - // 将同名的历史聊天对象删除,再执行下面的addRecent,确保每一个对象只在列表中出现一个 - this->removeRecentItem(mac); - - // 添加到最近聊天列表 - QString ip_mac = buddy->data(BuddyListItemModel::Ip).toString(); - if (files->size() == 1) - mRecentList.addRecent(files->at(0), d.absoluteFilePath(files->at(0)), "file", userName, totalSize, ip_mac); - else - mRecentList.addRecent("Files and folders", d.absolutePath(), "misc", userName, totalSize, ip_mac); - - delete files; - files = NULL; - - // 界面新消息提醒 - newMsgAlert(mac); -} - -// 一次文字接收完成 -/* -* Parameters: -* text: text msg -* mac: mac address -* Return : -*/ -void GuiBehind::receiveTextComplete(QString text, QString mac){ - qDebug() << "mac : " << mac << "text" << text ; - QStandardItem *buddy = NULL; - buddy = mBuddiesList.buddyByMac(mac); - qDebug() << "buddy" << buddy; - - QString userName; - QString ip_mac; - if(buddy != NULL) - { - userName = buddy->data(BuddyListItemModel::Username).toString(); - ip_mac = buddy->data(BuddyListItemModel::Ip).toString(); - qDebug() << "username :" << userName << "ip_mac :" << ip_mac; - } - - - // 已有该对话框,直接append - if(this->cws.contains(mac)){ - ChatWidget *cw = this->cws.value(mac); - cw->addTextLog(text); - - // 没有该对话框,先保存在tmpMsgs中 - }else{ - QDateTime time = QDateTime::currentDateTime(); - QString tHead= ""; - tHead += userName; - tHead += " ("; - tHead += time.toString("hh:mm:ss"); - tHead += ")"; - - if(this->tmpMsgs.contains(mac)){ - QStringList tmpList = this->tmpMsgs.value(mac); - tmpList.append(tHead); - tmpList.append(text); - this->tmpMsgs.insert(mac, tmpList); - }else{ - QStringList tmpList; - tmpList.append(tHead); - tmpList.append(text); - this->tmpMsgs.insert(mac, tmpList); - } - } - - // 将同名的历史聊天对象删除,再执行下面的addRecent,确保每一个对象只在列表中出现一个 - this->removeRecentItem(mac); - - // 添加到最近聊天列表 - mRecentList.addRecent("Text snippet", text, "text", userName, 0, ip_mac); - - // 界面新消息提醒 - newMsgAlert(mac); -} - -// 删除最近聊天列表中的指定条目 -/* -* Parameters: -* mac: mac address -* Return : -*/ -void GuiBehind::removeRecentItem(QString mac){ - for (int i = 0; i < mRecentList.rowCount(); i ++) { - QStandardItem *oneItem = mRecentList.item(0); - QVariant sender = oneItem->data(RecentListItemModel::Mac); - QStringList mac_list = sender.toString().split(" "); - if (mac_list.count() >= 2) { - QString mac_ = mac_list.at(1); - if(mac == mac_){ - mRecentList.removeRow(i); - break; - } - } - } -} - -// 显示聊天对话窗口 -/* -* Parameters: -* ip_mac: ip and mac address string -* Return : -*/ -void GuiBehind::showSendPage(QString ip_mac) -{ - qDebug()<<"打开聊天窗口:"<cws.contains(mac)){ - foreach (ChatWidget *cw_, this->cws){ - cw_->focusOut(); - } - - ChatWidget *cw = this->cws.value(mac); - cw->showme(); - cw->show(); - cw->raise(); - cw->focusIn(); - - // 使用wmctrl命令切换聊天窗口 - QString wmcmd = "wmctrl -a " + cw->windowTitle(); - system(wmcmd.toUtf8().data()); - - // 创建新实例 - }else{ - ChatWidget *cw = createCW(mac); - cw->showme(); - cw->show(); - } - - // 停止头像动画和任务栏动画 - buddy->setData(false, BuddyListItemModel::ShowMsgAnim); - this->alertTimer->stop(); -// this->mView->setWindowIcon(this->iconDukto); -} - -// 创建新的对话框实例 -/* -* Parameters: -* mac: mac address -* Return : -*/ -ChatWidget * GuiBehind::createCW(QString mac){ - QStandardItem *buddy = mBuddiesList.buddyByMac(mac); - ChatWidget *cw = new ChatWidget(); - cw->theme = &mTheme; - cw->buddies = &(mBuddiesList.mItemsMap); - cw->dbuddy->fillFromItem(buddy); - mIpAddresses.refreshIpList(); - cw->myIp = mIpAddresses.myIp; - cw->firstStyle(); - connect(cw, SIGNAL(reSaveCw(QString)), this, SLOT(reSaveCw(QString))); - connect(cw, SIGNAL(reBindSocket(ChatWidget*)), mDuktoProtocol, SLOT(connectSocketAndChatWidget(ChatWidget*))); - - this->cws.insert(QString(mac), cw); - - // 有tmp消息,全部append到对话框中 - if(this->tmpMsgs.contains(mac)){ - QStringList tmpList = this->tmpMsgs.value(mac); - for(int i = 0; i < tmpList.length(); i ++){ - QString msg = tmpList[i]; - cw->addLogDirect(msg); - } - this->tmpMsgs.remove(mac); - } - - // 多对话框初始位置偏移 - if(this->cwx == -1){ - QDesktopWidget* desktop = QApplication::desktop(); - this->cwx = (desktop->width() - cw->width()) / 2; - this->cwy = (desktop->height() - cw->height()) / 2; - }else{ - this->cwx += 25; - this->cwy += 25; - } - cw->move(this->cwx, this->cwy); - - return cw; -} - -// 使用IP发送消息成功,将map中的"IP"键替换为该mac,此后才能继续打开IP输入窗口 -void GuiBehind::reSaveCw(QString mac){ - if(this->cws.contains(mac) == false){ - ChatWidget *cw = this->cws.value("MAC"); - this->cws.insert(mac, cw); - } - - this->cws.remove("MAC"); -} - -// 激活头像动画提醒 -void GuiBehind::newMsgAlert(QString mac){ - // 没有打开与该用户的对话框 - if(this->cws.contains(mac) == false || this->cws.value(mac)->isHidden() == true){ - QStandardItem *item = mBuddiesList.buddyByMac(mac); - if(item != NULL){ - // 激活头像提示 - item->setData(true, BuddyListItemModel::ShowMsgAnim); - } - // 激活任务栏提示 - this->alertTimer->start(); - //TODO: check QtQuick 2 alert -// QApplication::alert(mView, 5000); - } -} - -// 更改接收文件目录 -void GuiBehind::changeDestinationFolder(){ -// QString dirname = QFileDialog::getExistingDirectory(mView, tr("Change folder"), ".", -// QString dirname = QFileDialog::getExistingDirectory(mView, "更改目录", ".", - QString dirname = QFileDialog::getExistingDirectory(nullptr, tr("Change folder"), ".", - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - if (dirname == "") return; - - // 将所选路径设置为当前程序环境默认路径 - QDir::setCurrent(dirname); - - // 保存路径 - setCurrentPath(dirname); -} - -// 保存路径 -void GuiBehind::setCurrentPath(QString path){ - if (path == mSettings->currentPath()) return; - mSettings->savePath(path); - emit currentPathChanged(); -} - -// 使用文件管理器打开文件接收目录 -void GuiBehind::openDestinationFolder(){ - QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::currentPath())); -} - -// 刷新本机IP -void GuiBehind::refreshIpList(){ - mIpAddresses.refreshIpList(); -} - -/* -* Summary: change theme color -* Parameters: -* color: target color -* Return : -*/ -void GuiBehind::changeThemeColor(QString color){ - mTheme.setThemeColor(color); - mSettings->saveThemeColor(color); - - // 将所有的聊天窗口同步主题颜色 - QMap::iterator iter = cws.begin(); - while (iter != cws.end()) { - iter.value()->showme(); - iter++; - } -} - -/* -* Summary: close app -* Return : -*/ -void GuiBehind::close(){ - mDuktoProtocol->sayGoodbye(); -} - -// 获取图标路径,qml访问本地图片需使用绝对路径 -QString GuiBehind::iconPath() -{ - return "file://" + mSettings->iconPath(); -} - -// 保存图标路径 -void GuiBehind::setIconPath(QString path) -{ - if (path == mSettings->iconPath()) - return; - mSettings->saveIconPath(path); -} - -// 获取应用版本号 -QString GuiBehind::appVersion() -{ - return qApp->applicationVersion(); -} - -/* -* Summary: say hello -* Return : -*/ -void GuiBehind::periodicHello(){ - mDuktoProtocol->sayHello(QHostAddress::Broadcast); -} - -QString GuiBehind::currentPath() -{ - return mSettings->currentPath(); -} - -// 将 byte 转换成 KB 或 MB -/* -* Parameters: -* size: size in byte -* Return : -*/ -QString GuiBehind::sizeHuman(qint64 size){ - QString sizeFormatted; - if (size < 1000) - sizeFormatted = QString::number(size) + " B"; - else if (size < 1000000) - sizeFormatted = QString::number(size * 1.0 / 1000, 'f', 1) + " KB"; - else - sizeFormatted = QString::number(size * 1.0 / 1000000, 'f', 1) + " MB"; - - return sizeFormatted; -} - -// 窗口 icon 闪烁 -void GuiBehind::msgAlert(){ -// if(this->timeFlag % 2 == 0){ -// this->mView->setIcon(this->iconBlank); -// }else{ -// this->mView->setIcon(this->iconDukto); -// } - this->timeFlag ++; -} - -// 查看用户手册 -void GuiBehind::viewUserGuide() -{ - if (!mDaemonIpcDbus->daemonIsNotRunning()){ - //增加标题栏帮助菜单、F1快捷键打开用户手册 - mDaemonIpcDbus->showGuide("kylin-ipmsg"); - } -} diff --git a/guibehind.h b/guibehind.h deleted file mode 100644 index 63961ed..0000000 --- a/guibehind.h +++ /dev/null @@ -1,215 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef GUIBEHIND_H -#define GUIBEHIND_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "buddylistitemmodel.h" -#include "recentlistitemmodel.h" -#include "ipaddressitemmodel.h" -#include "theme.h" -#include "chatwidget.h" -#include "peer.h" -#include "ksocket.h" -#include "daemonipcdbus.h" - -#define NETWORK_PORT 9696 -#define UDP_BROADCAST 0x01 -#define UDP_UNICAST 0x02 -#define UDP_GOODBYE 0x03 - -class MiniWebServer; -class Settings; -class DuktoWindow; -class QNetworkAccessManager; -class QNetworkReply; -class DuktoProtocol; -class KTcpServer; - - -class GuiBehind : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString currentPath READ currentPath NOTIFY currentPathChanged) - Q_PROPERTY(QString iconPath READ iconPath WRITE setIconPath NOTIFY iconPathChanged) - Q_PROPERTY(QString appVersion READ appVersion NOTIFY appVersionChanged) - -public: - explicit GuiBehind(DuktoWindow* view); - virtual ~GuiBehind(); - - // 管理所有的Tcp连接 - /**/ - QMap sockets; - // 好友列表界面model - BuddyListItemModel mBuddiesList; - // 管理所有的聊天窗口 - QMap cws; - QMap tmpMsgs; - - inline Settings* settings() { return mSettings; } - QString currentPath(); - void setCurrentPath(QString path); - QString sizeHuman(qint64 size); - void close(); - - // app icon in about qml - // 关于界面的图标路径 - QString iconPath(); - void setIconPath(QString path); - - // app version in about qml - // 关于界面的版本号 - QString appVersion(); - void setAppVersion(QString path); - - ChatWidget * createCW(QString mac); - -signals: - void currentPathChanged(); - void iconPathChanged(); - void appVersionChanged(); - -public slots: - void periodicHello(); - void peerListAdded(Peer peer); - void peerListRemoved(Peer peer); - - void openDestinationFolder(); - void refreshIpList(); - void changeDestinationFolder(); - void showSendPage(QString ip_mac); - void changeThemeColor(QString color); - - void sendTextComplete_add_recentlist(QString text , QString mac); - void receiveTextComplete(QString text, QString mac); - void receiveFileComplete(QStringList *files, qint64 totalSize, QString dir, QString mac); - void reSaveCw(QString ip); - void newMsgAlert(QString mac); - void removeRecentItem(QString mac); - void msgAlert(); - - // 查看用户手册 - void viewUserGuide(); - -private: - DuktoWindow *mView; - QTimer *mPeriodicHelloTimer; - MiniWebServer *mMiniWebServer; - Settings *mSettings; - RecentListItemModel mRecentList; - IpAddressItemModel mIpAddresses; - DuktoProtocol *mDuktoProtocol; - Theme mTheme; - - DaemonIpcDbus *mDaemonIpcDbus; - - int cwx; - int cwy; - int timeFlag; - QTimer *alertTimer; - QIcon iconDukto; - QIcon iconBlank; -}; - - -class DuktoProtocol : public QObject -{ - Q_OBJECT - -public: - DuktoProtocol(GuiBehind *gb); - virtual ~DuktoProtocol(); - void initialize(); - void sayHello(QHostAddress dest); - void sayGoodbye(); - - // 废弃的KSocket列表 - QList discardSockets; - - GuiBehind *gbehind; - - QString pSystemSignature; - -public slots: - void newUdpData(); - void newIncomingConnection(qintptr socketDescriptor); - void newOutgoingConnection(QString targetIP, QString remoteID, ChatWidget *cw); - void updateRemoteID(QString ip, QString user_name , QString system , QString mac , QString Platform , KSocket*); - void updateSockets(QString pRemoteID); - void addUpBuddy(QString ip, QString user_name , QString system , QString mac , QString Platform); - - // 绑定聊天窗口和socket - void connectSocketAndChatWidget(ChatWidget *); - -signals: - void peerListAdded(Peer peer); - void peerListRemoved(Peer peer); - -private: - QString getSystemSignature(); - QString getMac(); - void sendToAllBroadcast(QByteArray *packet); - void handleMessage(QByteArray &data, QHostAddress &sender); - - QUdpSocket *mSocket; - KTcpServer *mTcpServer; - - /**/ - QHash mPeers; -}; - - -class KTcpServer : public QTcpServer -{ - Q_OBJECT -public: - KTcpServer(); - -protected: - void incomingConnection(qintptr socketDescriptor); - -signals: - void newConn(qintptr socketDescriptor); -}; - -#endif // GUIBEHIND_H diff --git a/ipaddressitemmodel.cpp b/ipaddressitemmodel.cpp deleted file mode 100644 index b8eee3d..0000000 --- a/ipaddressitemmodel.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "ipaddressitemmodel.h" - - -IpAddressItemModel::IpAddressItemModel() : - QStandardItemModel(NULL) -{ - QHash roleNames; - roleNames[Ip] = "ip"; - setItemRoleNames(roleNames); - - refreshIpList(); -} - -/* -* Summary: add a ip address -* Parameters: -* ip: ip address -* Return : -*/ -void IpAddressItemModel::addIp(QString ip) -{ - QStandardItem* it = new QStandardItem(); - it->setData(ip, IpAddressItemModel::Ip); - appendRow(it); -} - -/* -* Summary: refresh ip list -* Return : -*/ -void IpAddressItemModel::refreshIpList() -{ - clear(); - - QList addrs = QNetworkInterface::allAddresses(); - for (int i = 0; i < addrs.length(); i++) - if ((addrs[i].protocol() == QAbstractSocket::IPv4Protocol) && (addrs[i].toString() != "127.0.0.1")){ - addIp(addrs[i].toString()); - - // 选择正确的局域网IP地址 - if (addrs[i].toString().left(3) == "192") { - this->myIp = addrs[i].toString(); - break; - } - else if (addrs[i].toString().left(3) == "172") { - this->myIp = addrs[i].toString(); - break; - } - else if (addrs[i].toString().left(2) == "10") { - this->myIp = addrs[i].toString(); - break; - } - } -} diff --git a/ipaddressitemmodel.h b/ipaddressitemmodel.h deleted file mode 100644 index 358aa2c..0000000 --- a/ipaddressitemmodel.h +++ /dev/null @@ -1,44 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef IPADDRESSITEMMODEL_H -#define IPADDRESSITEMMODEL_H - -#include -#include -#include - - -class IpAddressItemModel : public QStandardItemModel -{ -public: - IpAddressItemModel(); - void refreshIpList(); - - enum IpRoles { - Ip = Qt::UserRole + 1 - }; - - QString myIp; - -private: - void addIp(QString ip); -}; - -#endif // IPADDRESSITEMMODEL_H diff --git a/ksocket.cpp b/ksocket.cpp deleted file mode 100644 index d6647ca..0000000 --- a/ksocket.cpp +++ /dev/null @@ -1,951 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "ksocket.h" - -/*server var constructors*/ -KSocket::KSocket(qintptr s, QString systemSignature , QObject *parent):QObject(parent) -{ - qDebug() << "server var create success"; - qDebug() << "server var structure args : socket fd : " << s << "this mach flag" << systemSignature; - - this->socket = NULL; - this->socketSecondary = NULL; - this->pTcpServer = NULL; - this->timer = NULL; - - this->socketDescriptor = s; - this->pSystemSignature = systemSignature; - this->isConnected = false; - - return; -} - -/* - * client var constructors - * Parameters: - * targetip : server ip - * systemsignature : localte system falg - * premoteid : server mac - * parent : parent object - */ -KSocket::KSocket(QString targetIP, QString systemSignature, QString pRemoteID, QObject *parent):QObject(parent) -{ - qDebug() << "client var create success"; - qDebug() << "client var structure args : server_ip : " << targetIP << "server_mac : " << pRemoteID << "this mach flag : " << systemSignature; - - this->pTargetIP = targetIP; - this->pSystemSignature = systemSignature; - this->pRemoteID = pRemoteID; - - this->socket = NULL; - this->socketSecondary = NULL; - this->pTcpServer = NULL; - this->timer = NULL; - - this->timeoutCount = 0; - this->isConnected = false; - - return; -} - -KSocket::~KSocket() -{ - qDebug() << "~KSocket"; - if (pReceivedFiles) { - delete pReceivedFiles; - pReceivedFiles = NULL; - } - - return; -} - -// 被动端开始工作 -void KSocket::imReady() -{ - /*get socket*/ - this->socket = new QTcpSocket(); - this->socket->setSocketDescriptor(this->socketDescriptor); - - /*establish interrupt*/ - connect(socket, SIGNAL(readyRead()), this, SLOT(handleMsg())); - connect(socket, SIGNAL(disconnected()), this, SLOT(finishThread())); - connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)), Qt::DirectConnection); - - qDebug()<<"server get socket . socket fd is : " << this->socketDescriptor << " thread is : " << QThread::currentThreadId(); - - /*init var*/ - this->pTargetIP = socket->peerAddress().toString(); - this->pTotalLenToReceive = 0; - this->pTotalReceivedLen = 0; - this->pReadType = MSGTYPE; - this->pReceivedFiles = new QStringList(); - this->isConnected = true; - this->isInitiative = false; - -#if 0 - /*create second socket*/ - this->pTcpServer = new QTcpServer(); - bool rtn = this->pTcpServer->listen(QHostAddress::AnyIPv4, NETWORK_PORT - 1); - if (rtn == false) { - qDebug() << "error : server listen socket create fail"; - } - connect(pTcpServer, SIGNAL(newConnection()), this, SLOT(newSecondaryConn())); - - qDebug() << "server listen socket create success . prot is listening"; - -#endif - - /*send system flag to client*/ - QString system_flag; - system_flag.clear(); - system_flag = this->pSystemSignature; - - std::string std_system_flag = system_flag.toStdString(); - const char *p_system_flag = std_system_flag.c_str(); - - socket->write(S_IAMREADY); - socket->write(p_system_flag); - socket->waitForBytesWritten(); - socket->flush(); - - qDebug() << "server system flag send to clien is success"; - - return; -} - -#if 0 -// 被动附socket连接 -void KSocket::newSecondaryConn() -{ - if (!pTcpServer->hasPendingConnections()) - return; - - this->socketSecondary = pTcpServer->nextPendingConnection(); - - connect(socketSecondary, SIGNAL(readyRead()), this, SLOT(handleMsgSecondary())); - connect(socketSecondary, SIGNAL(disconnected()), this, SLOT(finishThread())); - - qDebug() << "server get second socket , socket is located thread : " << QThread::currentThreadId(); -} -#endif - -// 主动端开始工作 -void KSocket::imStart() -{ - /*client get socket*/ - socket = new QTcpSocket(); - - /*establish interrupt*/ - connect(socket , SIGNAL(connected()) , this , SLOT(imStart_())); - connect(socket , SIGNAL(readyRead()) , this , SLOT(handleMsg())); - connect(socket , SIGNAL(disconnected()) , this , SLOT(finishThread())); - connect(socket , SIGNAL(error(QAbstractSocket::SocketError)) , this , SLOT(socketError(QAbstractSocket::SocketError)) , Qt::DirectConnection); - - socket->connectToHost(this->pTargetIP, NETWORK_PORT); - - qDebug() << "client linking server......"; - - // 超时计时器 - timer = new QTimer(this); - connect(timer , SIGNAL(timeout()) , this , SLOT(timoutOnce())); - timer->start(3000); - - return; -} - -// 主动连接单次超时处理 -void KSocket::timoutOnce() -{ - timeoutCount++; - - qDebug() << "发起Tcp连接超时 " << timeoutCount<< " 次"; - - // 超时次数到,向主界面发送超时信号 - if (timeoutCount > 3) { - disconnect(timer , SIGNAL(timeout()) , this , SLOT(timoutOnce())); - if (this->timer != NULL) { - delete this->timer; - this->timer = NULL; - } - isConnected = false; - - emit transferMsgSignal(CONN_TIMEOUT); - - qDebug() << "超时次数过多,连接失败..."; - - } else { - socket->abort(); - socket->connectToHost(this->pTargetIP, NETWORK_PORT); - - qDebug() << "this->pTargetIP" << this->pTargetIP; - qDebug() << "client linking server ......"; - } - - return; -} - -// 主动连接成功,取消超时计时器 -void KSocket::imStart_() -{ - disconnect(timer, SIGNAL(timeout()), this, SLOT(timoutOnce())); - timer->stop(); - if (this->timer != NULL) { - delete this->timer; - this->timer = NULL; - } - - isConnected = true; - isInitiative = true; - - this->pTotalLenToReceive = 0; - this->pTotalReceivedLen = 0; - this->pReadType = MSGTYPE; - this->pReceivedFiles = new QStringList(); - - emit transferMsgSignal(CONN_SUCCESS); - - qDebug() << "client get socket . thread: " << QThread::currentThreadId() << " socket: " << socket; - - return; -} - -#if 0 -void KSocket::client_second_socket_establish() -{ - qDebug() << "client second socket establish success"; - qDebug() << "client get second socket"; - emit transferMsgSignal(CONN_SUCCESS); -} -#endif - -/* - * 消息处理函数 - * 消息头为16进制,一次信息由两类消息构成:头,数据 - * 接收方每收到一个文件,发送ENDONE告知发送方 - * - * 文字: 第一条消息:TEXT;第二条消息:DATA - * 文件: (第一条消息:FILE 或 DIR;第二条消息:DATA) * N;第三条消息:END - * - * TEXT: A0A1 + 9位总长度 - * FILE: A0A2 + 9位总长度 + 9位本条长度 + 9位文件名长度 + 文件名 - * DIR:A0A3 + 9位文件夹名长度 + 文件夹名 - * DATA:A0A0 + 变长数据 - * END:A0A9 - * ENDONE:A0A8 - * - * WHOAMI:A0B1 + 变长数据 - * - */ -void KSocket::handleMsg() -{ - qDebug() << "KSocket::handleMsg()"; - - while (socket->bytesAvailable() > 0) { - - if (this->pReadType == MSGTYPE) { - if (socket->bytesAvailable() < MSG_SIZE_MIN) { - qDebug() << "\n本条消息长度错误 wrong msg size: " << socket->bytesAvailable(); - return; - } - - // 读取msgType - QByteArray msgType = socket->read(4); - socket->flush(); - QString mt = QString::fromUtf8(msgType); - - /*client receicve server ready msg*/ - if (mt == S_IAMREADY) { - /*read server system flag*/ - qDebug() << "---clien receive server iamready flag"; - QByteArray system_falg = socket->readAll(); - QString tmp(system_falg); - QStringList flag = tmp.split(" "); - if (flag.count() > 4) { - QString mac = flag.at(3); - QString ip = socket->peerAddress().toString(); - QString user_name = flag.at(1); - QString system = flag.at(2); - QString platfrom = flag.at(4); - - /*Reassignment this->pRemotID*/ - this->pRemoteID = mac; - - qDebug() << "s_iamready : " << "\n" << "ip is " << ip << "\n" << "user_name = " << user_name << "\n" << "system = " << system << "\n" << "mac = " << mac << "\n" << "platfrom = " << platfrom; - - emit addUpBuddy(ip , user_name , system , mac , platfrom); - } - - /*client send system flag to server*/ - QString system_flag; - system_flag.clear(); - system_flag = this->pSystemSignature; - - std::string std_system_flag = system_flag.toStdString(); - const char *p_system_flag = std_system_flag.c_str(); - - socket->write(C_WHOAMI); - socket->write(p_system_flag); - socket->waitForBytesWritten(); - socket->flush(); - - qDebug() << "client send system flag to server is success"; - -#if 0 - /*client get second socket*/ - socketSecondary = new QTcpSocket(); - - connect(socketSecondary, SIGNAL(readyRead()), this, SLOT(handleMsgSecondary())); - connect(socketSecondary, SIGNAL(disconnected()), this, SLOT(finishThread())); - connect(socketSecondary, SIGNAL(connected()), this, SLOT(client_second_socket_establish())); - - socketSecondary->connectToHost(this->pTargetIP, NETWORK_PORT - 1); -#endif - } - /*server recevie client c_whoami msg*/ - else if (mt == C_WHOAMI) { - qDebug() << "---server receive clien c_whoami flag"; - - QByteArray system_falg = socket->readAll(); - QString tmp(system_falg); - QStringList flag = tmp.split(" "); - if (flag.count() > 4) { - QString mac = flag.at(3); - QString ip = socket->peerAddress().toString(); - QString user_name = flag.at(1); - QString system = flag.at(2); - QString platfrom = flag.at(4); - - qDebug() << "c_whoami" << "\n" << "ip is " << ip << "\n" << "user_name = " << user_name << "\n" << "system = " << system << "\n" << "mac = " << mac << "\n" << "platfrom = " << platfrom; - - /*Reassignment this->pRemotID*/ - this->pRemoteID = mac; - - emit updateRemoteID(ip , user_name , system , mac , platfrom , this); - } - - emit transferMsgSignal(CONN_SUCCESS); - } - // 文字消息头 - else if (mt == C_TEXT) { - this->pCurrentMsgType = C_TEXT; - this->pReadType = DATA; - - this->pTotalLenToReceive = socket->read(9).toInt(NULL, 16); - this->pReceiveText = ""; - } - // 文件消息头 - else if (mt == C_FILE) { - this->pCurrentMsgType = C_FILE; - this->pReadType = DATA; - - this->pCurrentMsgReceivedLen = 0; - - this->pTotalLenToReceive = socket->read(9).toLongLong(NULL, 16); - this->pCurrentMsgLen = socket->read(9).toLongLong(NULL, 16); - int fileNameLen = socket->read(9).toInt(NULL, 16); - QString name = QString::fromUtf8(socket->read(fileNameLen)); - - // 本文件为发送文件夹中的文件,将根目录改为重命名之后的 - if ((name.indexOf('/') != -1) && (name.section("/", 0, 0) == pRootDir)){ - name = name.replace(0, name.indexOf('/'), pRootDirRename); - } - - // 如果文件重名,则重命名 - int i = 2; - QString originalName = name; - while (QFile::exists(name)) { - QFileInfo fi(originalName); - name = fi.baseName() + " (" + QString::number(i) + ")." + fi.completeSuffix(); - i++; - } - - this->pReceiveFile = new QFile(name); - - bool ret = this->pReceiveFile->open(QIODevice::WriteOnly); - if (!ret){ - emit transferMsgSignal(7); - } - - // 该文件大小为0,只创建,不进入DATA接收步骤 - if(pCurrentMsgLen == 0){ - this->pReceivedFiles->append(pReceiveFile->fileName()); - pReceiveFile->close(); - //delete pReceiveFile; - pReceiveFile->deleteLater(); - pReceiveFile = NULL; - - // 使用附socket告知对方,单个文件接收完成,可以发送下一个文件 - QString endOne = C_END_ONEFILE; - - /*remove second tcp link , change to use one tcp link*/ - //socketSecondary->write(endOne.toUtf8().data()); - //socketSecondary->flush(); - - socket->write(endOne.toUtf8().data()); - socket->flush(); - - this->pReadType = MSGTYPE; - } - - emit startTransfer(false); - } - // 文件夹消息头 - else if (mt == C_DIR) { - this->pCurrentMsgType = C_DIR; - - int dirNameLen = socket->read(9).toInt(NULL, 16); - QString name = QString::fromUtf8(socket->read(dirNameLen)); - - // 根目录 - if(name.indexOf("/") == -1){ - // 如果文件夹重名,则重命名 - int i = 2; - QString originalName = name; - while (QFile::exists(name)) - name = originalName + " (" + QString::number(i++) + ")"; - - this->pRootDir = originalName; - this->pRootDirRename = name; - } - // 子目录 - else{ - name = name.mid(this->pRootDir.length()); - name = this->pRootDirRename + name; - } - - // 创建文件夹 - QDir dir("."); - bool ret = dir.mkpath(name); - if (!ret){ - emit transferMsgSignal(6); - } - - this->pReceivedFiles->append(name); - - // 使用附socket告知对方,单个文件夹接收完成,可以发送下一个 - QString endOne = C_END_ONEDIR; - - /*remove second tcp link , change to use one tcp link*/ - //socketSecondary->write(endOne.toUtf8().data()); - //socketSecondary->flush(); - - socket->write(endOne.toUtf8().data()); - socket->flush(); - } - // 本次信息结束符 - else if (mt == C_END) { - if (this->pCurrentMsgType == C_TEXT) { - qDebug() << "一次文本信息接收完毕: " << QString::fromUtf8(this->pReceiveText); - - emit receiveTextComplete(QString::fromUtf8(this->pReceiveText), this->pRemoteID); - - this->pTotalReceivedLen = 0; - - }else if (this->pCurrentMsgType == C_FILE || this->pCurrentMsgType == C_DIR) { - qDebug() << "一次文件传输接收完毕: " << this->pTotalLenToReceive << " " << this->pTotalReceivedLen; - - QStringList *listToShow = new QStringList(); - listToShow->append(*pReceivedFiles); - emit receiveFileComplete(listToShow, this->pTotalReceivedLen, this->pRootDirRename, this->pRemoteID); - - this->pRootDir = ""; - this->pRootDirRename = ""; - this->pTotalReceivedLen = 0; - this->pReceivedFiles->clear(); - - } else { - qDebug()<<"\n1本条数据结束符消息类型错误 wrong end msg type: "<pCurrentMsgType; - emit transferMsgSignal(7); - } - } - else if (mt == C_END_ONEFILE) { - this->sendOneFile(); - } - else if (mt == C_END_ONEDIR) { - this->sendDirs(); - } - else if (mt == C_CANCEL) { - // 告知聊天界面是否主动连接 - emit isInitiativeConn(this->isInitiative); - emit receiveFileCancelled(); - // 断开连接,解绑废弃ksocket - qDebug() << "handleMsgSecondary"; - this->finishThread(); - break; - } - else { -// qDebug()<<"\n2本条消息头类型错误 wrong head msg type: "<pCurrentMsgType == C_TEXT) { - this->receiveText(); - } else if (this->pCurrentMsgType == C_FILE) { - this->receiveFile(); - } else { - qDebug()<<"\n3本条数据消息类型错误 wrong data msg type: "<pCurrentMsgType; - emit transferMsgSignal(9); - } - } - } -} - -#if 0 -// 附属 socket 消息处理 -void KSocket::handleMsgSecondary(){ - while (socketSecondary->bytesAvailable() > 0){ - if(socketSecondary->bytesAvailable() < MSG_SIZE_MIN){ - qDebug()<<"\nsocketSecondary本条消息长度错误 wrong msg size: "<bytesAvailable(); - break; - } - - // 读取msgType - QByteArray msgType = socketSecondary->read(4); - socketSecondary->flush(); - QString mt = QString::fromUtf8(msgType); - - // 单个文件接收完成响应 - if(mt == C_END_ONEFILE){ - this->sendOneFile(); - } - - // 单个文件夹接收完成响应 - else if(mt == C_END_ONEDIR){ - this->sendDirs(); - } - - // 文件传输取消响应 - else if(mt == C_CANCEL){ - // 告知聊天界面是否主动连接 - emit isInitiativeConn(this->isInitiative); - emit receiveFileCancelled(); - // 断开连接,解绑废弃ksocket - qDebug() << "handleMsgSecondary"; - this->finishThread(); - break; - } - - else{ - qDebug()<<"\n2socketSecondary本条消息头类型错误 wrong head msg type: "<bytesAvailable() > leftLen) ? leftLen : socket->bytesAvailable(); - - QByteArray data = socket->read(readLen); - pTotalReceivedLen += readLen; - pReceiveText.append(data); - - // 约定长度已经全部读取完成,将接收模式置为MSGTYPE,等待END消息 - if (pTotalReceivedLen == pTotalLenToReceive) { - this->pReadType = MSGTYPE; - } -} - -// 接收单个文件 -void KSocket::receiveFile() -{ - // 计算本次接收长度 - qint64 leftLen = pCurrentMsgLen - pCurrentMsgReceivedLen; - qint64 readLen = (socket->bytesAvailable() > leftLen) ? leftLen : socket->bytesAvailable(); - - QByteArray data = socket->read(readLen); - pCurrentMsgReceivedLen += readLen; - pTotalReceivedLen += readLen; - pReceiveFile->write(data); - - // 更新进度条 - int percent = this->pTotalReceivedLen * 100.0 / this->pTotalLenToReceive; - QString text = this->sizeHuman(this->pTotalReceivedLen) + " / " + this->sizeHuman(this->pTotalLenToReceive); - emit updateTransferStatus(percent, text, false); - - // 单个文件已经全部读取完成 - if (pCurrentMsgReceivedLen == pCurrentMsgLen) { - this->pReceivedFiles->append(pReceiveFile->fileName()); - pReceiveFile->close(); - //delete pReceiveFile; - pReceiveFile->deleteLater(); - pReceiveFile = NULL; - - // 使用附socket告知对方,单个文件接收完成,可以发送下一个文件 - /*remove second tcp link , change to use one tcp link*/ - char p_buff[1024]; - memset(p_buff , 0x00 , sizeof(p_buff)); - strcpy(p_buff , C_END_ONEFILE); - - socket->write(p_buff); - socket->waitForBytesWritten(); - socket->flush(); - this->pReadType = MSGTYPE; - } -} - -// 发送文字消息 -void KSocket::sendText(QString text) -{ - if (this->isConnected == true) { - QString head = C_TEXT; - head.append(this->comLen(text)); - socket->write(head.toUtf8().data()); - - socket->write(text.toUtf8().data()); - - QString end = C_END; - socket->write(end.toUtf8().data()); - socket->flush(); - - qDebug() << "发送成功"; - emit sendTextComplete(); - emit sendTextComplete_add_recentlist(text , this->pRemoteID); - } - else { - emit transferMsgSignal(DISCONN); - } -} - -// 发送文件夹预处理 -void KSocket::sendDir(QString dir) -{ - if(this->isConnected == true){ - this->tmpFiles.clear(); - this->pDirsToSend.clear(); - this->pRootPath = dir.left(dir.lastIndexOf("/") + 1); - - this->listAllFiles(dir); - - this->sendDirs(); - } - else { - emit transferMsgSignal(DISCONN); - } -} - -// 递归获取所有文件夹和文件路径 -void KSocket::listAllFiles(QString fileName) -{ - QFileInfo fi(fileName); - - if (fi.isFile()) { - this->tmpFiles.append(fileName); - } - - if (fi.isDir()) { - this->pDirsToSend.append(fileName); - - QStringList entries = QDir(fileName).entryList(QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot); - for (int i = 0; i < entries.count(); i++) { - this->listAllFiles(fileName + "/" + entries.at(i)); - } - } -} - -// 发送文件夹消息 -void KSocket::sendDirs() -{ - if (this->isConnected == true) { - if (this->pDirsToSend.size() != 0) { - QString head = C_DIR; - QString dir = this->pDirsToSend.at(0); - QString dirRalative = dir.mid(this->pRootPath.length()); - head.append(this->comLen(dirRalative)); - head.append(dirRalative); - this->pDirsToSend.removeFirst(); - - socket->write(head.toUtf8().data()); - } - else { - // 全部文件夹发送完成,开始发送文件 - this->sendFiles(this->tmpFiles); - } - } - else { - emit transferMsgSignal(TRANSFERERR); - } -} - -// 发送文件预处理 -void KSocket::sendFiles(QStringList files) -{ - if (this->isConnected == true) { - bool isSkipFile = false; - this->pFilesToSend.clear(); - this->pTotalLenToSend = 0; - this->pTotalSendLen = 0; - - for(int i = 0; i < files.size(); i ++){ - QFile *file = new QFile(files.at(i)); - QFileInfo finfo(*file); - - if(finfo.isReadable() == true) { - if(finfo.isSymLink() == false) { - this->pTotalLenToSend += file->size(); - this->pFilesToSend.append(file); - } else { - qDebug()<<"该文件是符号链接,跳过: "<fileName(); - isSkipFile = true; - } - } else { - qDebug()<<"你没有该文件的读权限,跳过: "<fileName(); - isSkipFile = true; - } - } - - if (this->pFilesToSend.size() != 0) { - emit startTransfer(true); - this->sendOneFile(); - - // 提示有跳过文件 - if(isSkipFile == true){ - emit transferMsgSignal(SKIPFILE); - } - } - } - else { - emit transferMsgSignal(DISCONN); - } -} - -// 发送单个文件 -void KSocket::sendOneFile() -{ - if (this->isConnected == true) { - if (this->pFilesToSend.size() != 0) { - this->pSendFile = this->pFilesToSend.at(0); - this->pCurrentFileLenToSend = this->pSendFile->size(); - this->pCurrentFileSendLen = 0; - this->pFilesToSend.removeFirst(); - this->sendFileHead(); - } - else { - // 全部文件发送完成,发送结束消息 - QString end = C_END; - socket->write(end.toUtf8().data()); - socket->flush(); - - this->pRootPath = ""; - - emit sendFileComplete(); - } - } - else { - emit transferMsgSignal(TRANSFERERR); - } -} - -// 发送文件消息头 -void KSocket::sendFileHead() -{ - if (this->isConnected == true) { - this->pSendFile->open(QIODevice::ReadOnly); - // 知识点: 调用waitForBytesWritten()不会触发bytesWritten()信号 - connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(sendData())); - - QString head = C_FILE; - head.append(this->formatLen(this->pTotalLenToSend)); - head.append(this->formatLen(this->pCurrentFileLenToSend)); - - // 无文件根目录,本次是发送文件ccc.txt - // /home/kylin/bbb/ccc.txt >> ccc.txt - if (this->pRootPath == "") { - head.append(this->comLen(this->pSendFile->fileName().section("/", -1, -1))); - head.append(this->pSendFile->fileName().section("/", -1, -1)); - } - // 有文件根目录,本次是发送文件夹bbb - // /home/kylin/bbb/ccc.txt >> bbb/ccc.txt - else { - head.append(this->comLen(this->pSendFile->fileName().mid(this->pRootPath.length()))); - head.append(this->pSendFile->fileName().mid(this->pRootPath.length())); - } - qDebug()<<"!!! "<write(head.toUtf8().data()); - } - else { - emit transferMsgSignal(TRANSFERERR); - } -} - -// 发送单个文件数据 -void KSocket::sendData() -{ - if (this->isConnected == true) { - - if ((this->pCurrentFileLenToSend - this->pCurrentFileSendLen) > 0) { - int sendLen = 0; - if ((this->pCurrentFileLenToSend - this->pCurrentFileSendLen) >= 10240) { - sendLen = 10240; - } else { - sendLen = this->pCurrentFileLenToSend - this->pCurrentFileSendLen; - } - - QByteArray data = this->pSendFile->read(sendLen); - - socket->write(data); - - this->pTotalSendLen += data.size(); - this->pCurrentFileSendLen += data.size(); - - // 更新进度条 - int percent = this->pTotalSendLen * 100.0 / this->pTotalLenToSend; - QString text = this->sizeHuman(this->pTotalSendLen) + " / " + this->sizeHuman(this->pTotalLenToSend); - emit updateTransferStatus(percent, text, true); - } - // 单个文件发送完成 - else { - disconnect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(sendData())); - - this->pSendFile->close(); -// delete this->pSendFile; - this->pSendFile->deleteLater(); - this->pSendFile = NULL; - } - } - else { - emit transferMsgSignal(TRANSFERERR); - } -} - -// 发送取消文件传输消息 -void KSocket::sendCancel() -{ - if (this->isConnected == true) { - QString head = C_CANCEL; - - //socketSecondary->write(head.toUtf8().data()); - //socketSecondary->flush(); - /*remove second tcp link , change to use one tcp link*/ - - socket->write(head.toUtf8().data()); - socket->flush(); - - // 告知聊天界面是否主动连接 - emit isInitiativeConn(this->isInitiative); - // 断开连接,解绑废弃ksocket - qDebug() << "sendCancel"; - this->finishThread(); - } - else { - emit transferMsgSignal(DISCONN); - } -} - -// 断开连接时的结束操作 -void KSocket::finishThread() -{ - qDebug() << "KSocket::finishThread()"; - - if (socket) { - disconnect(socket, SIGNAL(disconnected()), this, SLOT(finishThread())); - } - -#if 0 - if (socketSecondary) { - disconnect(socketSecondary, SIGNAL(disconnected()), this, SLOT(finishThread())); - } -#endif - - qDebug() << "this->isConnected" << this->isConnected; - - if(this->isConnected == true){ - this->isConnected = false; - - if (socket) { - socket->close(); - socket->deleteLater(); - socket = NULL; - } - -#if 0 - if(socketSecondary){ - socketSecondary->close(); - socketSecondary->deleteLater(); - socketSecondary = NULL; - } -#endif - - qDebug() << this->isInitiative; - if (this->isInitiative == false && pTcpServer) { - pTcpServer->close(); - qDebug() << "pTcpServer close"; -// delete pTcpServer; - // caoliang 防止内存泄露 - pTcpServer->deleteLater(); - qDebug() << "delete pTcpServer"; - pTcpServer = NULL; - } - -// emit finished(); - qDebug() << "emit finished()"; - emit finished(this->pRemoteID); - qDebug() << "emit finished(this->pRemoteID)"; - emit finished(false); - qDebug() << "emit finished(false)"; - } - qDebug() << "out out KSocket::finishThread()"; -} - -// socket标准错误处理 -void KSocket::socketError(QAbstractSocket::SocketError se) -{ - qDebug() << "KSocket::socketError()"; - qDebug()<<"socket错误:"<formatLen(msgByte.length()); -} - -// 将10进制数字转换成9位长的16进制数的字符串 -QString KSocket::formatLen(qint64 len) -{ - QString lens = QString::number(len, 16); - for(int i = lens.length(); i < 9 ; i ++){ - lens = "0" + lens; - } - return lens; -} diff --git a/ksocket.h b/ksocket.h deleted file mode 100644 index 2247af0..0000000 --- a/ksocket.h +++ /dev/null @@ -1,231 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef KSOCKETTHREAD_H -#define KSOCKETTHREAD_H - -#include -#include -#include -#include -#include -#include -#include - -#include "settings.h" - -// 消息类型 -#define C_WHOAMI "A0B1" -#define C_TEXT "A0A1" -#define C_FILE "A0A2" -#define C_DIR "A0A3" -#define C_END_ONEFILE "A0A7" -#define C_END_ONEDIR "A0A8" -#define C_END "A0A9" -#define C_CANCEL "A0FF" -#define S_IAMREADY "B0B1" -#define S_ERROR "B0FF" - -#define NETWORK_PORT 9696 -#define MSG_SIZE_MIN 4 - - -class KSocket : public QObject -{ - Q_OBJECT -public: - KSocket(qintptr s, QString systemSignature, QObject *parent = 0); - KSocket(QString targetIP, QString systemSignature, QString pRemoteID, QObject *parent = 0); - ~KSocket(); - - // 本机系统标识 - QString pSystemSignature; - // 对方标识 - QString pRemoteID; - // 目标IP - QString pTargetIP; - // 连接超时次数 - int timeoutCount; - // socket是否在线 - bool isConnected; - // 主动连接或被动连接 - bool isInitiative; - - // 被告知的本次信息总长度 - qint64 pTotalLenToReceive; - // 当前信息已接收的总长度 - qint64 pTotalReceivedLen; - // 被告知的当前单条消息长度 - qint64 pCurrentMsgLen; - // 当前消息已接收部分的长度 - qint64 pCurrentMsgReceivedLen; - // 接收的文字 - QByteArray pReceiveText; - // 当前接收的文件夹的根目录 - QString pRootDir; - // 文件夹已存在,重命名后的根目录 - QString pRootDirRename; - // 当前接收的文件 - QFile *pReceiveFile; - // 本次接收的所有文件列表 - QStringList *pReceivedFiles; - - // 当前发送的文件 - QFile *pSendFile; - // 根文件夹所在目录 - QString pRootPath; - // 当前要发送的文件夹列表 - QStringList pDirsToSend; - // 预处理文件列表 - QStringList tmpFiles; - // 当前要发送的文件列表 - QList pFilesToSend; - // 当前要发送的所有文件总长度 - qint64 pTotalLenToSend; - // 当前已发送的所有文件总长度 - qint64 pTotalSendLen; - // 当前发送的单个文件长度 - qint64 pCurrentFileLenToSend; - // 当前已发送的单个文件长度 - qint64 pCurrentFileSendLen; - - // 当前读取内容类型 - enum readType { - MSGTYPE, - DATA - } pReadType; - // 当前消息类型 - QString pCurrentMsgType; - - // socket相关 - QTcpSocket *socket; - QTcpSocket *socketSecondary; - QTcpServer *pTcpServer; - qintptr socketDescriptor; - // 连接超时计时器 - QTimer *timer; - - // 接收文字 - void receiveText(); - // 接收文件 - void receiveFile(); - -private: - // 遍历出目标文件夹下所有文件名 - void listAllFiles(QString fileName); - // 将byte转换成KB或MB - QString sizeHuman(qint64 size); - // 计算消息长度,并转换成9位长的16进制数的字符串 - QString comLen(QString msg); - // 将10进制数字转换成9位长的16进制数的字符串 - QString formatLen(qint64 len); - -public slots: - //void client_second_socket_establish(); - // 被动端开始工作 - void imReady(); - // 被动附socket连接 - //void newSecondaryConn(); - // 主动端开始工作 - void imStart(); - // 单次超时处理 - void timoutOnce(); - // 连接成功,取消超时计时器,执行初始化方法 - void imStart_(); - // 发送文字 - void sendText(QString); - // 发送文件夹预处理 - void sendDir(QString); - // 发送文件夹 - void sendDirs(); - // 发送文件预处理 - void sendFiles(QStringList); - // 发送单个文件 - void sendOneFile(); - // 发送单个文件头 - void sendFileHead(); - // 发送实际数据 - void sendData(); - // 发送取消文件传输消息 - void sendCancel(); - // 断开连接时的结束操作 - void finishThread(); - - // socket标准错误处理 - void socketError(QAbstractSocket::SocketError); - - /* - * 消息处理函数 - * 消息头为16进制,一次信息由两类消息构成:头,数据 - * 接收方每收到一个文件,发送ENDONE告知发送方 - * - * 文字: 第一条消息:TEXT;第二条消息:DATA - * 文件: (第一条消息:FILE 或 DIR;第二条消息:DATA) * N;第三条消息:END - * - * TEXT: A0A1 + 9位总长度 - * FILE: A0A2 + 9位总长度 + 9位本条长度 + 9位文件名长度 + 文件名 - * DIR:A0A3 + 9位文件夹名长度 + 文件夹名 - * DATA:A0A0 + 变长数据 - * END:A0A9 - * ENDONE:A0A8 - * - * WHOAMI:A0B1 + 变长数据 - * - */ - void handleMsg(); - //void handleMsgSecondary(); - -signals: - // 文字发送完成信号 - void sendTextComplete(); - void sendTextComplete_add_recentlist(QString , QString); - // 文件发送完成信号 - void sendFileComplete(); - // 文件发送取消信号 - void sendFileCancelled(); - - // 文字接收完成信号 - void receiveTextComplete(QString text, QString); - // 文件接收完成信号 - void receiveFileComplete(QStringList *files, qint64 totalSize, QString dir, QString remoteID); - // 文件接收取消信号 - void receiveFileCancelled(); - // 是否主动连接 - void isInitiativeConn(bool); - // 添加上层好友 - void addUpBuddy(QString ip, QString user_name , QString system , QString mac , QString Platform); - - // 开启进度条,true:发送,false:接收 - void startTransfer(bool isSend); - // 更新进度条状态,true:发送,false:接收 - void updateTransferStatus(int percent, QString text, bool isSend); - - // 自报姓名消息 - //void updateRemoteID(QString pRemoteID, KSocket *ks); - void updateRemoteID(QString ip, QString user_name , QString system , QString mac , QString Platform , KSocket*); - // 异常消息 - void transferMsgSignal(int code); - - // 断开连接信号 - void finished(); - void finished(QString); - void finished(bool); -}; - -#endif // KSOCKETTHREAD_H diff --git a/ktcpserver.cpp b/ktcpserver.cpp deleted file mode 100644 index 97716b6..0000000 --- a/ktcpserver.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "guibehind.h" - - -KTcpServer::KTcpServer() -{ - this->setMaxPendingConnections(200); -} - -/* -* Summary: incoming a new connection -* Parameters: -* socketdescriptor: qt socket descriptor -* Return : -*/ -void KTcpServer::incomingConnection(qintptr socketDescriptor){ - qDebug() << "incomingConnection" << socketDescriptor; - emit newConn(socketDescriptor); -} diff --git a/ktcpserver.h b/ktcpserver.h deleted file mode 100644 index 96ada11..0000000 --- a/ktcpserver.h +++ /dev/null @@ -1,36 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef KTCPSERVER_H -#define KTCPSERVER_H - -#include -#include - -class KTcpServer : public QTcpServer -{ - Q_OBJECT -public: - KTcpServer(); - -protected: - void incomingConnection(int socketDescriptor); -}; - -#endif // KTCPSERVER_H diff --git a/kylin-ipmsg-old.png b/kylin-ipmsg-old.png deleted file mode 100644 index 7a3f5b0..0000000 Binary files a/kylin-ipmsg-old.png and /dev/null differ diff --git a/kylin-ipmsg.pro b/kylin-ipmsg.pro deleted file mode 100644 index 2ee03f3..0000000 --- a/kylin-ipmsg.pro +++ /dev/null @@ -1,97 +0,0 @@ -# DUKTO - A simple, fast and multi-platform file transfer tool for LAN users -# Copyright (C) 2011 Emanuele Colombo -# 2020 KylinSoft Co., Ltd. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -include(qmlapplicationviewer/qmlapplicationviewer.pri) - -QT += core gui network dbus - -lessThan(QT_MAJOR_VERSION, 5) { - QT += declarative -} else { - QT += widgets quick qml -} - -#for nullptr -greaterThan(QT_MAJOR_VERSION, 4): CONFIG += c++11 - -QMAKE_CXXFLAGS += -g - -TRANSLATIONS = kylin-ipmsg_zh_CN.ts - -TARGET = kylin-ipmsg - -target.path = /usr/bin -target.source += $$TARGET -icon.path = /usr/share/pixmaps -icon.files = kylin-ipmsg.png -desktop.path = /usr/share/applications/ -desktop.files = kylin-ipmsg.desktop -guide.path = /usr/share/kylin-user-guide/data/guide/ -guide.files = data/guide/kylin-ipmsg/ - -INSTALLS += target \ - icon \ - desktop \ - guide - -SOURCES += main.cpp \ - guibehind.cpp \ - platform.cpp \ - buddylistitemmodel.cpp \ - duktoprotocol.cpp \ - miniwebserver.cpp \ - ipaddressitemmodel.cpp \ - recentlistitemmodel.cpp \ - settings.cpp \ - destinationbuddy.cpp \ - duktowindow.cpp \ - theme.cpp \ - chatwidget.cpp \ - ktcpserver.cpp \ - ksocket.cpp \ - daemonipcdbus.cpp - -HEADERS += \ - guibehind.h \ - platform.h \ - buddylistitemmodel.h \ - peer.h \ - miniwebserver.h \ - ipaddressitemmodel.h \ - recentlistitemmodel.h \ - settings.h \ - destinationbuddy.h \ - duktoprotocol.h \ - duktowindow.h \ - theme.h \ - chatwidget.h \ - ksocket.h \ - daemonipcdbus.h - -FORMS += \ - chatwidget.ui - -RESOURCES += \ - qml.qrc - -include(qtsingleapplication/qtsingleapplication.pri) - -lupdate_only{ - SOURCES = qml/dukto/*.qml -} diff --git a/kylin-ipmsg_zh_CN.qm b/kylin-ipmsg_zh_CN.qm deleted file mode 100644 index 3329cf5..0000000 Binary files a/kylin-ipmsg_zh_CN.qm and /dev/null differ diff --git a/kylin-ipmsg_zh_CN.ts b/kylin-ipmsg_zh_CN.ts deleted file mode 100644 index 67fc65b..0000000 --- a/kylin-ipmsg_zh_CN.ts +++ /dev/null @@ -1,290 +0,0 @@ - - - - - AboutPage - - - Kylin Ipmsg - 麒麟传书 - - - - Provide text chat and file transfer function with no server. - 本软件提供局域网内的文字聊天以及文件传输功能,不需要搭建服务器 - - - - Mult person concurrency. - 支持多人同时交互,收发并行 - - - - The UI resources comes from Dukto - 界面素材来自开源软件 Dukto - - - - ChatWidget - - - Kylin Ipmsg - 麒麟传书 - - - - Send Text (Enter) - 发消息(Enter) - - - - Send Files - 传文件 (可多选) - - - - Send Dir - 传文件夹 - - - - Chat Widget - 消息界面 - - - - Sending files... - 正在发送文件 - - - - Cancel - 取消 - - - - Receiving files... - 正在接收文件 - - - - Change nickname - 修改备注 - - - - Confirm change - 确认修改 - - - The Remote IP Addr - Please input the remote IP address - 请输入对方的 IP 地址 - - - Show Remote IP Addr - 对方的 IP 地址 - - - Me - - - - file sent out - 发送了文件 - - - dir sent out - 发送了文件夹 - - - This is your Ip Addr - 这是你自己的IP地址 - - - IP already exist in buddies - 已有该IP好友,请点击好友打开聊天界面 - - - Illegal IP address - 输入的IP地址不合法 - - - Remoter has stoped the transfer - 对方中止了文件传输 - - - pls choose files to send - 请选择要发送的文件 - - - pls choose dir to send - 请选择要发送的文件夹 - - - pls do not send empty dir - 请勿发送空文件夹 - - - transmission canceled - 文件传输已取消 - - - conn failed, try again later - 连接失败,请确认好友在线,稍后再试 - - - transmission error - 数据传输错误 - - - connecting... - 正在尝试连接 - - - - DuktoWindow - - Kylin Ipmsg - 麒麟传书 - - - - GuiBehind - - (You) - (本机) - - - Use IP Address - 使用 IP 地址 - - - Received file - 收到文件 - - - files - - - - size - 大小 - - - Open directory - 打开目录 - - - Received folder - 收到文件夹 - - - Open - 打开 - - - Total size - 共计大小 - - - Contact with parent network - 向你的上层网络发送消息 - - - Change folder - 更改目录 - - - - IpPage - - - Your IP Address - 本机 IP 地址 - - - - RecentPage - - - Sorry, there is nothing yet... - 对不起, 您还没有收到过任何消息... - - - - Recent - 最近交谈 - - - - SettingsPage - - - Settings - 选项设置 - - - - File Receive Path - File Recive Path - 文件保存目录 - - - - Change Path - 更改目录 - - - - Theme Color - 主题颜色 - - - - User Guide - 用户手册 - - - - View Guide - 查看手册 - - - - TabBar - - - Buddy - 好 友 - - - - Recent - 最 近 - - - - About - 关 于 - - - - ToolBar - - - Received Files - 已接收文件 - - - - My IP Addr - 本机IP地址 - - - - Settings - 选项设置 - - - diff --git a/kylin-messages.pro b/kylin-messages.pro new file mode 100644 index 0000000..a16e4a6 --- /dev/null +++ b/kylin-messages.pro @@ -0,0 +1,35 @@ +TEMPLATE = subdirs +SUBDIRS = \ + plugins \ + src \ + +# translations +TRANSLATIONS += \ + data/translations/kylin-messages_zh_CN.ts +!system($$PWD/data/translations/generate_translations_pm.sh): error("Failed to generate pm") +qm_files.files = data/translations/*.qm +qm_files.path = /usr/share/kylin-messages/data/translations/ + +# gsettings +schemes.files += \ + $$PWD/data/schemas/org.kylin-messages-data.gschema.xml \ + $$PWD/data/schemas/org.ukui.log4qt.kylin-messages.gschema.xml +schemes.path = /usr/share/glib-2.0/schemas/ + +desktop.files = data/kylin-messages.desktop +desktop.path = /usr/share/applications/ + +INSTALLS += \ + desktop \ + schemes \ + qm_files + +# V10Pro使用自定义用户手册 +greaterThan(QT_MAJOR_VERSION, 5) | greaterThan(QT_MINOR_VERSION, 9) { + # message("QT_VERSION ("$$QT_VERSION")") + DEFINES += __V10Pro__ + guide.path = /usr/share/kylin-user-guide/data/guide/ + guide.files = data/guide/kylin-messages/ + + INSTALLS += guide +} \ No newline at end of file diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 8c2a7ca..0000000 --- a/main.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include -#include -#include -#include -#include - -#include "qtsingleapplication.h" -#include "qmlapplicationviewer.h" -#include "guibehind.h" -#include "duktowindow.h" - -/* -#include -#include -#include -#include -#include -*/ - -int main(int argc, char *argv[]) -{ -// QApplication::setGraphicsSystem("raster"); - - // 适配4K屏 - #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - #endif - - // 需要给QtSingleApplication的传入参数id加DISPLAY标识 - QString id = QString("kylin-ipmsg"+ QLatin1String(getenv("DISPLAY"))); - - /*lock file*/ - QtSingleApplication app(id, argc, argv); - app.setApplicationVersion("1.1.20"); - -// QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); -// QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); -// QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - - // 国际化 - QString locale = QLocale::system().name(); - QTranslator trans_global, trans_menu; - if(locale == "zh_CN"){ - trans_global.load(":/qml/kylin-ipmsg_zh_CN.qm"); -// trans_global.load(":/qml/kylin-ipmsg_bo_CN.qm"); - trans_menu.load(":/qml/qt_zh_CN.qm"); - app.installTranslator(&trans_global); - app.installTranslator(&trans_menu); - } - -#ifndef QT_NO_TRANSLATION - QString translatorFileName = QLatin1String("qt_"); - translatorFileName += QLocale::system().name(); - QTranslator *translator = new QTranslator(); - if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - app.installTranslator(translator); - else - qDebug() << "Failed to load Chinese translation file."; -#endif - -#if 0 -{ - /*add file lock*/ - struct flock s_lock; - s_lock.l_type = F_WRLCK; - s_lock.l_whence = SEEK_SET; - s_lock.l_start = 0; - s_lock.l_len = 0; - s_lock.l_pid = getpid(); - - char p_lock_file_dir[512]; - char p_lock_file_path[1024]; - char *p_home = NULL; - int i_ret = -1; - int fd = -1; - - memset(p_lock_file_dir , 0x00 , sizeof(p_lock_file_dir)); - memset(p_lock_file_path , 0x00 , sizeof(p_lock_file_path)); - - p_home = getenv("HOME"); - if(p_home == NULL) { - printf("get env var HOME fail\n"); - return -1; - } - - sprintf(p_lock_file_dir , "%s/.kylin-ipmsg" , p_home); - sprintf(p_lock_file_path , "%s/kylin-ipmsg.lock" , p_lock_file_dir); - - i_ret = access(p_lock_file_dir , F_OK); - if (i_ret == -1) { - printf("lock file path is not exits\n"); - i_ret = mkdir(p_lock_file_dir , 0777); - if(i_ret == -1) { - printf("create dir fail\n"); - return -1; - } - printf("create dir success\n"); - } - - fd = open(p_lock_file_path , O_CREAT | O_RDWR | O_TRUNC , 0777); - if(fd == -1) { - printf("get file fd fail\n"); - return -1; - } - i_ret = fcntl(fd , F_SETLK , &s_lock); - if (i_ret == -1) { - printf("lock file fail . errno is %s\n" , strerror(errno)); - return -1; - } -} -#endif - - // 单例判断 - /*check file whether locked*/ - if (app.isRunning()) { - app.sendMessage("FOREGROUND"); - return 0; - } -// app.setWindowIcon(QIcon("/usr/share/pixmaps/kylin-ipmsg.png")); - app.setWindowIcon(QIcon::fromTheme("kylin-ipmsg")); - - /*inherit qmlapplicationviewer and link dbus open kylin guide manual*/ - DuktoWindow viewer; - -// app.setActivationWindow(&viewer, true); - - /*init and udp , tcp listing and online broadcast*/ - /*udp broadcast is one byte and systemflag*/ - /*udp read is create item*/ - /*tcp active link is example ksocket in a thread*/ - /*tcp passive link is example ksocket in a thread*/ - /*ksocket class maintain two socket*/ - /*one ksocket example is a chatwidget*/ - /*tcp passive link is create second tcp server*/ - /*real socket in ksocket*/ - GuiBehind gb(&viewer); - - viewer.showExpanded(); - viewer.raise(); - app.installEventFilter(&gb); - - return app.exec(); -} diff --git a/miniwebserver.cpp b/miniwebserver.cpp deleted file mode 100644 index 1a2289d..0000000 --- a/miniwebserver.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "miniwebserver.h" -#include "platform.h" - - -MiniWebServer::MiniWebServer() -{ - // 获取用户头像文件 - QString path = Platform::getAvatarPath(); - if (path != "") - { - QImage img(path); - QImage scaled = img.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - QBuffer tmp(&mAvatarData); - tmp.open(QIODevice::WriteOnly); - scaled.save(&tmp, "PNG"); - } -} - -// 新进连接 -/* -* Parameters: -* handle: new connection handle -* Return : -*/ -void MiniWebServer::incomingConnection(qintptr handle) -{ - qDebug() << "MiniWebServer::incomingConnection"; - QTcpSocket* s = new QTcpSocket(this); - connect(s, SIGNAL(readyRead()), this, SLOT(readClient())); - connect(s, SIGNAL(disconnected()), this, SLOT(discardClient())); - s->setSocketDescriptor(handle); -} - -/* -* Summary: read clinet -* Return : -*/ -void MiniWebServer::readClient() -{ - QTcpSocket* socket = (QTcpSocket*)sender(); - if (socket->canReadLine()) { - QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*")); - if (tokens[0] == "GET") { - - QTextStream os(socket); - os.setAutoDetectUnicode(true); - os << "HTTP/1.0 200 OK\r\n" - "Content-Type: image/png\r\n" - "Content-Length: " << mAvatarData.size() << "\r\n" - "\r\n"; - os.flush(); - - QDataStream ds(socket); - ds.writeRawData(mAvatarData.data(), mAvatarData.size()); - - socket->close(); - if (socket->state() == QTcpSocket::UnconnectedState) - { -// delete socket; - socket->deleteLater(); - socket = NULL; - } - } - } -} - -/* -* Summary: discard a clinet -* Return : -*/ -void MiniWebServer::discardClient() -{ - qDebug() << "discardClient"; - QTcpSocket* socket = (QTcpSocket*)sender(); - socket->deleteLater(); -} diff --git a/miniwebserver.h b/miniwebserver.h deleted file mode 100644 index 63cdc02..0000000 --- a/miniwebserver.h +++ /dev/null @@ -1,54 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef MINIWEBSERVER_H -#define MINIWEBSERVER_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "guibehind.h" - - -class MiniWebServer : public QTcpServer -{ - Q_OBJECT - -public: - MiniWebServer(); - -protected: - virtual void incomingConnection(qintptr handle); - -private slots: - void readClient(); - void discardClient(); - -private: - QByteArray mAvatarData; - -}; - -#endif // MINIWEBSERVER_H diff --git a/peer.h b/peer.h deleted file mode 100644 index 7e39cda..0000000 --- a/peer.h +++ /dev/null @@ -1,53 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef PEER_H -#define PEER_H - -#include - -class Peer -{ - -public: - Peer() { } - - QString username; - QString system; - QString platform; - QHostAddress address; - QString mac; - qint16 port; - - inline Peer(QHostAddress a, QString n, qint16 p) { - QStringList data = n.split(" "); - - if(data.size() >= 5){ - username = data.at(1); - system = data.at(2); - mac = data.at(3); - platform = data.at(4); - } - - address = a; - port = p; - } -}; - -#endif // PEER_H diff --git a/platform.cpp b/platform.cpp deleted file mode 100644 index d385911..0000000 --- a/platform.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "platform.h" - -#include -#include -#include -#include -#include -#include - -#if defined(Q_WS_MAC) -#include -#include -#endif - -#if defined(Q_WS_WIN) -#include -#include - -typedef struct _USER_INFO_24 { - BOOL usri24_internet_identity; - DWORD usri24_flags; - LPWSTR usri24_internet_provider_name; - LPWSTR usri24_internet_principal_name; - PSID usri24_user_sid; -} USER_INFO_24, *PUSER_INFO_24, *LPUSER_INFO_24; - - -#endif - -#if defined(Q_WS_S60) -#define SYMBIAN -#include -QTM_USE_NAMESPACE -#endif - -#if defined(Q_WS_SIMULATOR) -#define SYMBIAN -#endif - -// Returns the system username -QString Platform::getSystemUsername() -{ -#if defined(SYMBIAN) - // Get username from settings - Settings s; - return s.buddyName(); -#else - - // Save in a static variable so that It's always ready - static QString username = ""; - if (username != "") return username; - -#if defined (Q_WS_WIN) -/* QString un(getenv("USERNAME")); - if (un != ""){ - USER_INFO_23 *user_info; - wchar_t buff[1024]; - int len = un.toWCharArray(buff); - buff[len] = '\0'; - NET_API_STATUS ret = NetUserGetInfo(NULL, buff, 23, (BYTE**)&user_info); - if (ret == ERROR_INVALID_LEVEL) { - QMessageBox::information(NULL, "1", "NOT SUPPORTED", QMessageBox::Ok); - } - else if (ret == ERROR_SUCCESS) { -*/ /*QMessageBox::information(NULL, "1", "SUCCESSO", QMessageBox::Ok); - QString dato = QString::fromWCharArray(user_info->usri24_internet_provider_name); - QMessageBox::information(NULL, "1", "A" + dato, QMessageBox::Ok); - dato = QString::fromWCharArray(user_info->usri24_internet_principal_name); - QMessageBox::information(NULL, "1", "B" + dato, QMessageBox::Ok);*/ -/* QString dato = QString::fromWCharArray(user_info->usri23_full_name); - QMessageBox::information(NULL, "1", "A" + dato, QMessageBox::Ok); - dato = QString::fromWCharArray(user_info->usri23_name); - QMessageBox::information(NULL, "1", "B" + dato, QMessageBox::Ok); - } - else { - QMessageBox::information(NULL, "1", "ERRORE", QMessageBox::Ok); - } -*/ /*else { - QString fullname = QString::fromWCharArray(user_info->usri24_internet_principal_name); - QMessageBox::information(NULL, "1", fullname, QMessageBox::Ok); - }*/ - /*fullname = QString::fromWCharArray(user_info->usri23_full_name); - QMessageBox::information(NULL, "1", fullname, QMessageBox::Ok);*/ -// } - -#endif - - // Looking for the username - QString uname(getenv("USERNAME")); - if (uname == "") uname = getenv("USER"); - if (uname == "") uname = "Unknown"; - uname = uname.left(1).toUpper() + uname.mid(1); - username = uname; - - return uname; -#endif -} - -// Returns the hostname -QString Platform::getHostname() -{ - // Save in a static variable so that It's always ready - static QString hostname = ""; - if (hostname != "") return hostname; - -#if defined(Q_WS_S60) - - QSystemDeviceInfo info; - hostname = info.model(); - -#else - - // Get the hostname - // (replace ".local" for MacOSX) - hostname = QHostInfo::localHostName().replace(".local", ""); - -#endif - - return hostname; -} - -// Returns the platform name -QString Platform::getPlatformName() -{ -#if defined(Q_WS_WIN) - return "Windows"; -#elif defined(Q_WS_MAC) - return "Macintosh"; -#elif defined(Q_OS_UNIX) - return "Linux"; -#elif defined(Q_WS_S60) - return "Symbian"; -#else - return "Unknown"; -#endif -} - -// Returns the platform avatar path -QString Platform::getAvatarPath() -{ -#if defined(Q_WS_WIN) - QString username = getSystemUsername().replace("\\", "+"); - QString path = QString(getenv("LOCALAPPDATA")) + "\\Temp\\" + username + ".bmp"; - if (!QFile::exists(path)) - path = getWinTempAvatarPath(); - if (!QFile::exists(path)) - path = QString(getenv("PROGRAMDATA")) + "\\Microsoft\\User Account Pictures\\Guest.bmp"; - if (!QFile::exists(path)) - path = QString(getenv("ALLUSERSPROFILE")) + "\\" + QDir(getenv("APPDATA")).dirName() + "\\Microsoft\\User Account Pictures\\" + username + ".bmp"; - if (!QFile::exists(path)) - path = QString(getenv("ALLUSERSPROFILE")) + "\\" + QDir(getenv("APPDATA")).dirName() + "\\Microsoft\\User Account Pictures\\Guest.bmp"; - return path; -#elif defined(Q_WS_MAC) - return getMacTempAvatarPath(); -#elif defined(Q_OS_UNIX) - return getLinuxAvatarPath(); -#elif defined(Q_WS_S60) - return ""; -#else - return ""; -#endif -} - -// Returns the platform default output path -QString Platform::getDefaultPath() -{ - // For Windows it's the Desktop folder -#if defined(Q_WS_WIN) - return QString(getenv("USERPROFILE")) + "\\Desktop"; -#elif defined(Q_WS_MAC) - return QString(getenv("HOME")) + "/Desktop"; -#elif defined(Q_OS_UNIX) - return QString(getenv("HOME")) + "/ReceivedFiles"; -#elif defined(Q_WS_S60) - return "E:\\Dukto"; -#elif defined(Q_WS_SIMULATOR) - return "D:\\"; -#elif defined(Q_OS_UNIX) - return QString(getenv("HOME")); -#else - #error "Unknown default path for this platform" -#endif - -} - -#if defined(Q_OS_UNIX) -// Special function for Linux -QString Platform::getLinuxAvatarPath() -{ - QString path; - - // Gnome2 check - path = QString(getenv("HOME")) + "/.face"; - if (QFile::exists(path)) return path; - - // Gnome3 check - QFile f("/var/lib/AccountsService/users/" + QString(getenv("USER"))); - if (!f.open(QFile::ReadOnly)) return ""; - QTextStream ts(&f); - QString line; - bool found = false; - while (true) { - line = ts.readLine(); - if (line.isNull()) break; - if (line.startsWith("Icon=")) { - QRegExp re("^Icon=(.*)$"); - if (re.indexIn(line) == -1) continue; - QStringList pathlist = re.capturedTexts(); - path = pathlist[1]; - found = true; - break; - } - } - f.close(); - if (found && QFile::exists(path)) return path; - - // Not found - return ""; -} -#endif - -#if defined(Q_WS_MAC) -static QTemporaryFile macAvatar; - -// Special function for OSX -QString Platform::getMacTempAvatarPath() -{ - // Get image data from system - QByteArray qdata; - CSIdentityQueryRef query = CSIdentityQueryCreateForCurrentUser(kCFAllocatorSystemDefault); - CFErrorRef error; - if (CSIdentityQueryExecute(query, kCSIdentityQueryGenerateUpdateEvents, &error)) { - CFArrayRef foundIds = CSIdentityQueryCopyResults(query); - if (CFArrayGetCount(foundIds) == 1) { - CSIdentityRef userId = (CSIdentityRef) CFArrayGetValueAtIndex(foundIds, 0); - CFDataRef data = CSIdentityGetImageData(userId); - qDebug() << CFDataGetLength(data); - qdata.resize(CFDataGetLength(data)); - CFDataGetBytes(data, CFRangeMake(0, CFDataGetLength(data)), (uint8*)qdata.data()); - } - } - CFRelease(query); - - // Save it to a temporary file - macAvatar.open(); - macAvatar.write(qdata); - macAvatar.close(); - return macAvatar.fileName(); -} -#endif - -#if defined(Q_WS_WIN) - -#include - -#define ARRAYSIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast(!(sizeof(a) % sizeof(*(a))))) - -typedef HRESULT (WINAPI*pfnSHGetUserPicturePathEx)( - LPCWSTR pwszUserOrPicName, - DWORD sguppFlags, - LPCWSTR pwszDesiredSrcExt, - LPWSTR pwszPicPath, - UINT picPathLen, - LPWSTR pwszSrcPath, - UINT srcLen -); - -// Special function for Windows 8 -QString Platform::getWinTempAvatarPath() -{ - // Get file path - CoInitialize(NULL); - HMODULE hMod = LoadLibrary(L"shell32.dll"); - pfnSHGetUserPicturePathEx picPathFn = (pfnSHGetUserPicturePathEx)GetProcAddress(hMod, (LPCSTR)810); - WCHAR picPath[500] = {0}, srcPath[500] = {0}; - HRESULT ret = picPathFn(NULL, 0, NULL, picPath, ARRAYSIZE(picPath), srcPath, ARRAYSIZE(srcPath)); - if (ret != S_OK) return "C:\\missing.bmp"; - QString result = QString::fromWCharArray(picPath, -1); - CoUninitialize(); - return result; -} - -#endif diff --git a/platform.h b/platform.h deleted file mode 100644 index 7ba7f60..0000000 --- a/platform.h +++ /dev/null @@ -1,50 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef PLATFORM_H -#define PLATFORM_H - -#include -#include -#include -#include - -class QString; - - -class Platform -{ -public: - static QString getSystemUsername(); - static QString getHostname(); - static QString getPlatformName(); - static QString getAvatarPath(); - static QString getDefaultPath(); - - Platform() {} -#if defined(Q_OS_UNIX) - static QString getLinuxAvatarPath(); -#elif defined(Q_WS_MAC) - static QString getMacTempAvatarPath(); -#elif defined(Q_WS_WIN) - static QString getWinTempAvatarPath(); -#endif -}; - -#endif // PLATFORM_H diff --git a/plugins/plugins.pro b/plugins/plugins.pro new file mode 100644 index 0000000..3a21487 --- /dev/null +++ b/plugins/plugins.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +# SUBDIRS = QtApng diff --git a/qml.qrc b/qml.qrc deleted file mode 100644 index 70a98c0..0000000 --- a/qml.qrc +++ /dev/null @@ -1,57 +0,0 @@ - - - qml/dukto/Klill-Light.ttf - qml/dukto/LiberationSans-Regular.ttf - qml/dukto/KGLikeASkyscraper.ttf - qml/dukto/ColorBox.qml - qml/dukto/SText.qml - qml/dukto/SmoothText.qml - qml/dukto/AboutPage.qml - qml/dukto/AppleLogo.png - qml/dukto/BackIcon.png - qml/dukto/BackIconDark.png - qml/dukto/TileGradient.png - qml/dukto/PanelGradient.png - qml/dukto/BottomShadow.png - qml/dukto/TopShadow.png - qml/dukto/BuddiesPage.qml - qml/dukto/BuddyListElement.qml - qml/dukto/Button.qml - qml/dukto/ButtonDark.qml - qml/dukto/ConfigIcon.png - qml/dukto/Dukto.qml - qml/dukto/DuktoInner.qml - qml/dukto/DuktoMetroIcon.png - qml/dukto/DuktoOverlay.qml - qml/dukto/IpLogo.png - qml/dukto/IpPage.qml - qml/dukto/LinuxLogo.png - qml/dukto/MoreIcon.png - qml/dukto/OpenFolderIcon.png - qml/dukto/PcLogo.png - qml/dukto/RecentFile.png - qml/dukto/RecentFiles.png - qml/dukto/RecentPage.qml - qml/dukto/RecentText.png - qml/dukto/SettingsPage.qml - qml/dukto/ShowIpIcon.png - qml/dukto/SmartphoneLogo.png - qml/dukto/SymbianLogo.png - qml/dukto/TabBar.qml - qml/dukto/ToolBar.qml - qml/dukto/UnknownLogo.png - qml/dukto/WindowsLogo.png - qml/dukto/IosLogo.png - qml/dukto/SBPicker.qml - qml/dukto/ColorPicker.qml - qml/dukto/ColorSlider.qml - qml/dukto/ColorUtils.js - qml/dukto/Blank.png - qml/qt_zh_CN.qm - qml/kylin-ipmsg-32.png - qml/kylin-ipmsg.png - qml/kylin-ipmsg-128.png - qml/kylin-ipmsg-c.png - qml/kylin-ipmsg_zh_CN.qm - - diff --git a/qml/dukto/AboutPage.qml b/qml/dukto/AboutPage.qml deleted file mode 100644 index ff20718..0000000 --- a/qml/dukto/AboutPage.qml +++ /dev/null @@ -1,71 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Item { - - Rectangle { - x: 27 - y: 15 - width: 64 - height: 64 - Image { - source: "TileGradient.png" - anchors.fill: parent - } - Image { -// source: "file:///usr/share/icons/ukui-icon-theme-default/64x64/apps/kylin-ipmsg.png" - source: guiBehind.iconPath - anchors.fill: parent - } - } - - SmoothText { - x: 22 - y: 85 - font.pixelSize: 72 - text: qsTr("Kylin Ipmsg") + " " + guiBehind.appVersion - color: theme.color4 - } - - SmoothText { - x: 25 - y: 135 - font.pixelSize: 32 - text: "http://www.kylinos.cn" - onLinkActivated: Qt.openUrlExternally(link) - color: theme.color5 - } - - SText { - anchors.right: parent.right - anchors.rightMargin: 40 - anchors.left: parent.left - anchors.leftMargin: 25 - y: 180 - font.pixelSize: 14 - color: theme.color5 - wrapMode: "WordWrap" - text: qsTr("Provide text chat and file transfer function with no server. ") + "\n" + - qsTr("Mult person concurrency. ") + "\n\n" + - qsTr("The UI resources comes from Dukto") - onLinkActivated: Qt.openUrlExternally(link) - } -} diff --git a/qml/dukto/AndroidLogo.png b/qml/dukto/AndroidLogo.png deleted file mode 100644 index 86af61d..0000000 Binary files a/qml/dukto/AndroidLogo.png and /dev/null differ diff --git a/qml/dukto/AppleLogo.png b/qml/dukto/AppleLogo.png deleted file mode 100644 index ca455c9..0000000 Binary files a/qml/dukto/AppleLogo.png and /dev/null differ diff --git a/qml/dukto/BackIcon.png b/qml/dukto/BackIcon.png deleted file mode 100644 index 32aaddd..0000000 Binary files a/qml/dukto/BackIcon.png and /dev/null differ diff --git a/qml/dukto/BackIconDark.png b/qml/dukto/BackIconDark.png deleted file mode 100644 index d1ef1eb..0000000 Binary files a/qml/dukto/BackIconDark.png and /dev/null differ diff --git a/qml/dukto/BackTile.png b/qml/dukto/BackTile.png deleted file mode 100644 index b15767b..0000000 Binary files a/qml/dukto/BackTile.png and /dev/null differ diff --git a/qml/dukto/BlackberryLogo.png b/qml/dukto/BlackberryLogo.png deleted file mode 100644 index 61b25bd..0000000 Binary files a/qml/dukto/BlackberryLogo.png and /dev/null differ diff --git a/qml/dukto/Blank.png b/qml/dukto/Blank.png deleted file mode 100644 index c7f16a2..0000000 Binary files a/qml/dukto/Blank.png and /dev/null differ diff --git a/qml/dukto/BottomShadow.png b/qml/dukto/BottomShadow.png deleted file mode 100644 index 46d99f6..0000000 Binary files a/qml/dukto/BottomShadow.png and /dev/null differ diff --git a/qml/dukto/BuddiesPage.qml b/qml/dukto/BuddiesPage.qml deleted file mode 100644 index 26b00b5..0000000 --- a/qml/dukto/BuddiesPage.qml +++ /dev/null @@ -1,55 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Item { - // 根据ip_mac地址停止好友界面对应item的头像动画 - function restoreMsgAnimByIp(ip_mac){ - for(var i = 0; i < buddiesList.count; i ++){ - buddiesList.currentIndex = i; - if(buddiesList.currentItem.buddyIp === ip_mac){ - buddiesList.currentItem.restoreIt(); - } - } - } - - clip: true - - ListView { - id: buddiesList - anchors.fill: parent - spacing: 10 - anchors.leftMargin: 25 - anchors.rightMargin: 0 - model: buddiesListData - - delegate: BuddyListElement { - buddyIp: ip - buddyAvatar: avatar - buddyGeneric: generic - buddyIpText: iptext - buddyUsername: username - buddySystem: system - buddyOsLogo: oslogo - buddyShowBack: showback - buddyShowMsgAnim: showMsgAnim - } - } -} diff --git a/qml/dukto/BuddyListElement.qml b/qml/dukto/BuddyListElement.qml deleted file mode 100644 index 849bfa8..0000000 --- a/qml/dukto/BuddyListElement.qml +++ /dev/null @@ -1,229 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Flipable { - id: contactDelegateItem - width: parent.width - height: buddyIp == "" ? 94 : 64 - - property string buddyIp - property alias buddyGeneric: buddyGenericImage.source - property alias buddyAvatar: buddyAvatarImage.source - property alias buddyOsLogo: buddyOsLogoImage.source - property alias buddyIpText: buddyIpText.text - property alias buddyUsername: buddyUsernameText.text - property alias buddySystem: buddySystemText.text - property bool buddyShowBack: false - property bool buddyShowMsgAnim: false - - // 检测鼠标悬停 - property bool buddyShowIp: buddyMouseArea.containsMouse - - function restoreIt(){ - restoreScale.start() - restoreOpacity.start() - } - - MouseArea { - id: buddyMouseArea - anchors.fill: parent - hoverEnabled: true - onClicked: { - guiBehind.showSendPage(buddyIp) - restoreScale.start() - restoreOpacity.start() - } - - } - - Rectangle { - anchors.fill: parent - color: "#00000000" - visible: buddyMouseArea.containsMouse; - Rectangle { - anchors.right: parent.right - anchors.top: parent.top - height: 64 - width: 5 - color: theme.color3 - } - } - - front: Item { - anchors.fill: parent - id: temp - width: contactDelegateItem.width - - Flipable { - id: flipableAvatar - width: 64 - height: 64 - - front: Rectangle { - anchors.fill: parent - color: theme.color2 - Image { - anchors.fill: parent - source: "TileGradient.png" - } - Image { - id: buddyGenericImage - anchors.fill: parent - } - Image { - id: buddyAvatarImage - anchors.fill: parent - smooth: true - } - } - - back: Rectangle { - anchors.fill: parent - color: theme.color2 - Image { - anchors.fill: parent - source: "TileGradient.png" - } - Image { - id: buddyOsLogoImage - anchors.fill: parent - } - } - - transform: Rotation { - id: innerRotation - origin.x: 32 - origin.y: 32 - axis.x: 0; axis.y: 0; axis.z: 1 - angle: 0 - } - - opacity:1 - - states: [ - State { - name: "MsgAnim" - when: buddyShowMsgAnim - } - ] - - transitions: [ - Transition { - from: "" - to: "MsgAnim" - SequentialAnimation { - NumberAnimation { target: flipableAvatar; property: "scale"; from: 0.5; to: 1.2; duration: 500; easing.type: Easing.InQuad;} - NumberAnimation { target: flipableAvatar; property: "scale"; from: 1.2; to: 0.5; duration: 500; easing.type: Easing.OutQuad;} - loops: Animation.Infinite - } - SequentialAnimation { - NumberAnimation { target: flipableAvatar; property: "opacity"; from: 0.3; to: 1; duration: 500; easing.type: Easing.InQuad;} - NumberAnimation { target: flipableAvatar; property: "opacity"; from: 1; to: 0.3; duration: 500; easing.type: Easing.OutQuad;} - loops: Animation.Infinite - } - } - ] - } - - SText { - id: buddyIpText - anchors.top: buddyUsernameText.bottom - anchors.topMargin: 8 - anchors.left: buddySystemText.right - anchors.leftMargin: 10 - wrapMode: Text.Wrap - font.pixelSize: 14 - elide: "ElideRight" - color: theme.color2 - // caoliang 隐藏或显示ip - visible: buddyShowIp - } - - SText { - id: buddyUsernameText - anchors.top: flipableAvatar.top - anchors.topMargin: 8 - anchors.left: flipableAvatar.right - anchors.leftMargin: 10 - anchors.right: parent.right - anchors.rightMargin: 20 - font.pixelSize: 18 - height: 21 - elide: "ElideRight" - color: theme.color2 - } - - SText { - id: buddySystemText - anchors.left: flipableAvatar.right - anchors.leftMargin: 10 - anchors.top: buddyUsernameText.bottom - anchors.topMargin: 8 -// anchors.right: parent.right - anchors.rightMargin: 10 - font.pixelSize: 14 - elide: "ElideRight" - color: theme.color4 - } - } - - transform: Rotation { - id: rotation - origin.x: 32 - origin.y: 32 - axis.x: 1; axis.y: 0; axis.z: 0 // set axis.y to 1 to rotate around y-axis - angle: 0 // the default angle - } - - ListView.onAdd: NumberAnimation { target: rotation; property: "angle"; from: -90; to: 0; duration: 300; easing.type: Easing.OutCubic } - ListView.onRemove: SequentialAnimation { - PropertyAction { target: contactDelegateItem; property: "ListView.delayRemove"; value: true } - NumberAnimation { target: rotation; property: "angle"; from: 0; to: -90; duration: 300; easing.type: Easing.InCubic } - PropertyAction { target: contactDelegateItem; property: "ListView.delayRemove"; value: false } - - } - - Rectangle { - color: theme.color2 - width: parent.width - 80 - height: 1 - x: (parent.width - width) / 2 - 10 - y: parent.height - 10 - visible: buddyIp == "" - } - - NumberAnimation { - id: restoreOpacity - target: flipableAvatar - properties: "opacity" - to: 1.0 - duration: 300 - } - - NumberAnimation { - id: restoreScale - target: flipableAvatar - properties: "scale" - to: 1.0 - duration: 300 - } - -} diff --git a/qml/dukto/Button.qml b/qml/dukto/Button.qml deleted file mode 100644 index 64cc041..0000000 --- a/qml/dukto/Button.qml +++ /dev/null @@ -1,50 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - id: button - width: 150 - height: 30 - border.color: buttonEnabled ? theme.color6 : theme.color7 - border.width: 2 - color: buttonArea.containsMouse ? (buttonArea.pressed ? theme.color7 : theme.color8) : "#00000000" - - property bool buttonEnabled: true - property alias label: textLabel.text - signal clicked() - - SText { - id: textLabel - anchors.fill: parent - color: buttonEnabled ? (buttonArea.containsMouse ? theme.color2 : theme.color6) : theme.color7 - horizontalAlignment: "AlignHCenter" - verticalAlignment: "AlignVCenter" - font.pixelSize: 12 - } - - MouseArea { - id: buttonArea - anchors.fill: parent - hoverEnabled: true - enabled: button.buttonEnabled - onClicked: button.clicked(); - } -} diff --git a/qml/dukto/ButtonDark.qml b/qml/dukto/ButtonDark.qml deleted file mode 100644 index 928c404..0000000 --- a/qml/dukto/ButtonDark.qml +++ /dev/null @@ -1,50 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - id: button - width: 150 - height: 30 - border.color: buttonEnabled ? theme.color2 : theme.color7 - border.width: 2 - color: buttonArea.containsMouse ? (buttonArea.pressed ? theme.color7 : theme.color8) : theme.color6 - - property bool buttonEnabled: true - property alias label: textLabel.text - signal clicked() - - SText { - id: textLabel - anchors.fill: parent - color: buttonEnabled ? theme.color2 : theme.color7 - horizontalAlignment: "AlignHCenter" - verticalAlignment: "AlignVCenter" - font.pixelSize: 12 - } - - MouseArea { - id: buttonArea - anchors.fill: parent - hoverEnabled: true - enabled: button.buttonEnabled - onClicked: button.clicked(); - } -} diff --git a/qml/dukto/ColorBox.qml b/qml/dukto/ColorBox.qml deleted file mode 100644 index a690599..0000000 --- a/qml/dukto/ColorBox.qml +++ /dev/null @@ -1,43 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - id: root - width: 32 - height: 32 - border.color: boxArea.containsMouse ? "#555555" : "#f0f0f0" - border.width: boxArea.containsMouse ? 2 : 2 - clip: true - - signal clicked(color color) - - Image { - anchors.fill: parent - source: "TileGradient.png" - } - - MouseArea { - id: boxArea - hoverEnabled: true - anchors.fill: parent - onClicked: root.clicked(parent.color) - } -} diff --git a/qml/dukto/ColorPicker.qml b/qml/dukto/ColorPicker.qml deleted file mode 100644 index 2952e23..0000000 --- a/qml/dukto/ColorPicker.qml +++ /dev/null @@ -1,85 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -// A toy QML colorpicker control, by Ruslan Shestopalyuk -import QtQuick 2.3 -import "ColorUtils.js" as ColorUtils - -Rectangle { - id: colorPicker - property color colorValue: ColorUtils.hsba(hueSlider.value, sbPicker.saturation, - sbPicker.brightness, 1) - width: 144; height: 126 - color: "#FFFFFF" - - signal changed() - - function setColor(color) { - - var h = theme.getHue(color); - var s = theme.getSaturation(color); - var b = theme.getLightness(color); - - hueSlider.setValue(h); - sbPicker.setValue(s, b); - - this.changed(); - } - - Row { - anchors.fill: parent - -// antialiasing: true; - spacing: 3 - - // saturation/brightness picker box - SBPicker { - id: sbPicker - hueColor : ColorUtils.hsba(hueSlider.value, 1.0, 1.0, 1.0, 1.0) - width: parent.height; height: parent.height - onChanged: { - colorPicker.changed(); - } - } - - // hue picking slider - Item { - width: 12; height: parent.height - Rectangle { - anchors.fill: parent - gradient: Gradient { - GradientStop { position: 1.0; color: "#FF0000" } - GradientStop { position: 0.85; color: "#FFFF00" } - GradientStop { position: 0.76; color: "#00FF00" } - GradientStop { position: 0.5; color: "#00FFFF" } - GradientStop { position: 0.33; color: "#0000FF" } - GradientStop { position: 0.16; color: "#FF00FF" } - GradientStop { position: 0.0; color: "#FF0000" } - } - border.color: "#f0f0f0" - border.width: 2 - } - ColorSlider { - id: hueSlider - anchors.fill: parent - onChanged: colorPicker.changed() - } - } - } -} diff --git a/qml/dukto/ColorSlider.qml b/qml/dukto/ColorSlider.qml deleted file mode 100644 index 78d6f7f..0000000 --- a/qml/dukto/ColorSlider.qml +++ /dev/null @@ -1,60 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -// Vertical "slider" control used in colorpicker -import QtQuick 2.3 -Item { - id: root - property real value: (1 - pickerCursor.y/height) - width: 15; height: 300 - - signal changed() - - function setValue(value) { - pickerCursor.y = (1 - value) * height; - } - - Item { - id: pickerCursor - width: parent.width - Rectangle { - x: -3; y: -height*0.5 - width: parent.width + 4; height: 7 - border.color: "black"; border.width: 1 - color: "transparent" - Rectangle { - anchors.fill: parent; anchors.margins: 2 - border.color: "white"; border.width: 1 - color: "transparent" - } - } - } - MouseArea { - anchors.fill: parent - function handleMouse(mouse) { - if (mouse.buttons & Qt.LeftButton) { - pickerCursor.y = Math.max(0, Math.min(height, mouse.y)) - root.changed(); - } - } - onPositionChanged: handleMouse(mouse) - onPressed: handleMouse(mouse) - } -} - diff --git a/qml/dukto/ColorUtils.js b/qml/dukto/ColorUtils.js deleted file mode 100644 index 9aca43f..0000000 --- a/qml/dukto/ColorUtils.js +++ /dev/null @@ -1,41 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -// Color manipulation utilities - -// creates color value from hue, saturation, brightness, alpha -function hsba(h, s, b, a) { - - var lightness = (2 - s)*b; - var satHSL = s*b/((lightness <= 1) ? lightness : 2 - lightness); - lightness /= 2; - - return Qt.hsla(h, satHSL, lightness, a); -} - -// creates a full color string from color value and alpha[0..1], e.g. "#FF00FF00" -function fullColorString(clr, a) { - return "#" + ((Math.ceil(a*255) + 256).toString(16).substr(1, 2) + - clr.toString().substr(1, 6)).toUpperCase(); -} - -// extracts integer color channel value [0..255] from color value -function getChannelStr(clr, channelIdx) { - return parseInt(clr.toString().substr(channelIdx*2 + 1, 2), 16); -} diff --git a/qml/dukto/ConfigIcon.png b/qml/dukto/ConfigIcon.png deleted file mode 100644 index a8bcdac..0000000 Binary files a/qml/dukto/ConfigIcon.png and /dev/null differ diff --git a/qml/dukto/Dukto.qml b/qml/dukto/Dukto.qml deleted file mode 100644 index 2b305dd..0000000 --- a/qml/dukto/Dukto.qml +++ /dev/null @@ -1,77 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - id: mainElement - width: 330 - height: 600 - - FontLoader { - id: duktofont - source: "Klill-Light.ttf" - } - - FontLoader { - id: duktofontsmall - source: "LiberationSans-Regular.ttf" - } - - FontLoader { - id: duktofonthappy - source: "KGLikeASkyscraper.ttf" - } - - DuktoInner { - id: duktoInner - anchors.fill: parent - onShowIpList: { - duktoOverlay.state = "ip" - ipPage.controlShowIpPage(); - } - - onShowSettings: { - duktoOverlay.refreshSettingsColor(); - duktoOverlay.state = "settings"; - settingsPage.controlSettingsPage(); - } - } - - DuktoOverlay { - id: duktoOverlay -// anchors.fill: parent - } - - IpPage { - id: ipPage - anchors.fill: parent - } - - SettingsPage { - id: settingsPage - anchors.fill: parent - } - - Binding { - target: guiBehind - property: "overlayState" - value: duktoOverlay.state - } -} diff --git a/qml/dukto/DuktoInner.qml b/qml/dukto/DuktoInner.qml deleted file mode 100644 index 0e813b5..0000000 --- a/qml/dukto/DuktoInner.qml +++ /dev/null @@ -1,138 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - state: "buddies" - color: theme.color6 - - signal showIpList() - signal showSettings() - - function gotoPage(page) { - tabBar.state = page; - state = page; - } - - function recentComponentClicked(mac) { - buddiesPage.restoreMsgAnimByIp(mac); - } - - TabBar { - id: tabBar - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - onClicked: parent.state = tab - } - - ToolBar { - id: toolBar - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - onClicked: { - if (command == "ip") showIpList(); - if (command == "settings") showSettings(); - } - } - - BuddiesPage { - id: buddiesPage - anchors.top: tabBar.bottom - anchors.topMargin: 10 - anchors.bottom: toolBar.top - width: parent.width - x: 200 - opacity: 0 - } - - RecentPage { - id: recentPage - anchors.top: tabBar.bottom - anchors.topMargin: 10 - anchors.bottom: toolBar.top - width: parent.width - x: parent.width - opacity: 0 - onComponentClicked: recentComponentClicked(mac) - } - - AboutPage { - id: aboutPage - anchors.top: tabBar.bottom - anchors.topMargin: 10 - anchors.bottom: toolBar.top - width: parent.width - x: parent.width - opacity: 0 - } - - states: [ - State { - name: "buddies" - - PropertyChanges { - target: buddiesPage - opacity: 1 - x: 0 - } - }, - State { - name: "recent" - PropertyChanges { - target: buddiesPage - opacity: 0 - x: -360 - } - PropertyChanges { - target: recentPage - opacity: 1 - x: 0 - } - }, - State { - name: "about" - - PropertyChanges { - target: buddiesPage - opacity: 0 - x: -360 - } - PropertyChanges { - target: recentPage - opacity: 0 - x: -360 - } - PropertyChanges { - target: aboutPage - opacity: 1 - x: 0 - } - } - ] - - transitions: [ - Transition { - NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuart; duration: 1000 } - NumberAnimation { properties: "opacity"; easing.type: Easing.InQuad; duration: 500 } - } - ] -} diff --git a/qml/dukto/DuktoMetroIcon.png b/qml/dukto/DuktoMetroIcon.png deleted file mode 100644 index ecdf53b..0000000 Binary files a/qml/dukto/DuktoMetroIcon.png and /dev/null differ diff --git a/qml/dukto/DuktoOverlay.qml b/qml/dukto/DuktoOverlay.qml deleted file mode 100644 index 2cc4b93..0000000 --- a/qml/dukto/DuktoOverlay.qml +++ /dev/null @@ -1,137 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - color: "#00000000" - - function refreshSettingsColor() { - settingsPage.refreshColor(); - } - - Rectangle { - id: disabler - anchors.fill: parent - color: theme.color9 - opacity: 0 - visible: false - - MouseArea { - anchors.fill: parent - } - } - - IpPage { - id: ipPage - anchors.top: parent.top - anchors.topMargin: 10 - anchors.bottom: parent.bottom - width: parent.width - x: -50 - opacity: 0 - visible: false - onBack: { - console.log("IpPage fanhui") - parent.state = "" - } - } - - SettingsPage { - id: settingsPage - width: parent.width - height: parent.height - x: -50 - opacity: 0 - anchors.fill: parent - visible: false - onBack: parent.state = "" -// onBack: { -// console.log("SettingsPage fanhui") -// SettingsPage.controlSettingsPage() -// } - } - - states: [ - State { - name: "ip" - PropertyChanges { - target: ipPage - opacity: 1 - x: 0 - } - PropertyChanges { - target: disabler - opacity: 1 - visible: true - } - }, - State { - name: "progress" - PropertyChanges { - target: progressPage - opacity: 1 - x: 0 - } - PropertyChanges { - target: disabler - opacity: 1 - visible: true - } - }, - // 收起进度条界面 - State { - name: "progress_" - PropertyChanges { - target: progressPage - opacity: 0 - x: -50 - } - PropertyChanges { - target: disabler - opacity: 0 - visible: false - } - }, - - State { - name: "settings" - PropertyChanges { - target: settingsPage - opacity: 1 - x: 0 - } - }, - State { - name: "send" - PropertyChanges { - target: sendPage - opacity: 1 - x: 0 - } - } - ] - - transitions: [ - Transition { - NumberAnimation { properties: "x,y"; easing.type: Easing.OutCubic; duration: 500 } - NumberAnimation { properties: "opacity"; easing.type: Easing.OutCubic; duration: 500 } - } - ] -} diff --git a/qml/dukto/IosLogo.png b/qml/dukto/IosLogo.png deleted file mode 100644 index a60b664..0000000 Binary files a/qml/dukto/IosLogo.png and /dev/null differ diff --git a/qml/dukto/IpLogo.png b/qml/dukto/IpLogo.png deleted file mode 100644 index 0f6d688..0000000 Binary files a/qml/dukto/IpLogo.png and /dev/null differ diff --git a/qml/dukto/IpPage.qml b/qml/dukto/IpPage.qml deleted file mode 100644 index 48f2080..0000000 --- a/qml/dukto/IpPage.qml +++ /dev/null @@ -1,133 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - id: ipPage - color: "#00000000" - - signal back() - - // 控制IP界面的显示与隐藏 - property bool showIpPage: false - visible: showIpPage - - function controlShowIpPage() { - showIpPage = !showIpPage - } - - - MouseArea { - anchors.fill: parent - } - - Item { - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left - anchors.right: parent.right - height: 200 - - Rectangle { - id: backRecangle - color: theme.color2 - anchors.left: parent.left - anchors.top: parent.top - anchors.bottom: parent.bottom -// width: 600 - anchors.right: parent.right - } - - Image { - source: "BottomShadow.png" - anchors.bottom: backRecangle.top - anchors.left: backRecangle.left - anchors.right: backRecangle.right - fillMode: Image.TileHorizontally - } - - Image { - source: "TopShadow.png" - anchors.top: backRecangle.bottom - anchors.left: backRecangle.left - anchors.right: backRecangle.right - fillMode: Image.TileHorizontally - } - - Image { - anchors.top: parent.top - anchors.left: parent.left - source: "PanelGradient.png" - } - - Image { - id: backIcon - source: "BackIcon.png" - anchors.top: parent.top - anchors.left: parent.left - anchors.topMargin: 5 - anchors.leftMargin: 5 - - MouseArea { - anchors.fill: parent -// onClicked: ipPage.back(); - onClicked: { -// parent.state = ""; - ipPage.controlShowIpPage(); - } - } - } - - SmoothText { - id: boxTitle - anchors.left: backIcon.right - anchors.top: parent.top - anchors.leftMargin: 15 - anchors.topMargin: 5 - font.pixelSize: 64 - text: qsTr("Your IP Address") - } - - ListView { - anchors.top: backIcon.bottom - anchors.left: boxTitle.left - anchors.right: parent.right - anchors.bottom: parent.bottom - anchors.topMargin: 20 - anchors.bottomMargin: 10 - clip: true - - model: ipAddressesData /*ListModel { - ListElement { ip: "192.168.92.32" } - ListElement { ip: "182.23.2.1" } - ListElement { ip: "169.0.3.2" } - } */ - - Component { - id: ipDelegate - SText { - text: ip - font.pixelSize: 17 - } - } - - delegate: ipDelegate - } - } -} diff --git a/qml/dukto/KGLikeASkyscraper.ttf b/qml/dukto/KGLikeASkyscraper.ttf deleted file mode 100644 index eaf1e1a..0000000 Binary files a/qml/dukto/KGLikeASkyscraper.ttf and /dev/null differ diff --git a/qml/dukto/Klill-Light.ttf b/qml/dukto/Klill-Light.ttf deleted file mode 100644 index a02195a..0000000 Binary files a/qml/dukto/Klill-Light.ttf and /dev/null differ diff --git a/qml/dukto/LiberationSans-Regular.ttf b/qml/dukto/LiberationSans-Regular.ttf deleted file mode 100644 index 59d2e25..0000000 Binary files a/qml/dukto/LiberationSans-Regular.ttf and /dev/null differ diff --git a/qml/dukto/LinuxLogo.png b/qml/dukto/LinuxLogo.png deleted file mode 100644 index 79ffcd0..0000000 Binary files a/qml/dukto/LinuxLogo.png and /dev/null differ diff --git a/qml/dukto/MoreIcon.png b/qml/dukto/MoreIcon.png deleted file mode 100644 index f522f2c..0000000 Binary files a/qml/dukto/MoreIcon.png and /dev/null differ diff --git a/qml/dukto/OpenFolderIcon.png b/qml/dukto/OpenFolderIcon.png deleted file mode 100644 index c123452..0000000 Binary files a/qml/dukto/OpenFolderIcon.png and /dev/null differ diff --git a/qml/dukto/PanelGradient.png b/qml/dukto/PanelGradient.png deleted file mode 100644 index 43bdb0f..0000000 Binary files a/qml/dukto/PanelGradient.png and /dev/null differ diff --git a/qml/dukto/PcLogo.png b/qml/dukto/PcLogo.png deleted file mode 100644 index 605e06b..0000000 Binary files a/qml/dukto/PcLogo.png and /dev/null differ diff --git a/qml/dukto/RecentFile.png b/qml/dukto/RecentFile.png deleted file mode 100644 index 332e63c..0000000 Binary files a/qml/dukto/RecentFile.png and /dev/null differ diff --git a/qml/dukto/RecentFiles.png b/qml/dukto/RecentFiles.png deleted file mode 100644 index 60e4c2b..0000000 Binary files a/qml/dukto/RecentFiles.png and /dev/null differ diff --git a/qml/dukto/RecentPage.qml b/qml/dukto/RecentPage.qml deleted file mode 100644 index 34fcf49..0000000 --- a/qml/dukto/RecentPage.qml +++ /dev/null @@ -1,132 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Item { - id: recentPage - clip: true - - signal showText(); - signal componentClicked(string mac); - - SmoothText { - id: badSmile - anchors.left: parent.left - anchors.leftMargin: 40 - anchors.top: parent.top - font.pixelSize: 100 -// text: ":-(" - text: "≥﹏≤" - color: theme.color4 - visible: (recentList.count == 0) - } - - SText { - y: badSmile.y + badSmile.height / 2 + 20 - // anchors.topMargin: 10 - anchors.left: parent.left - anchors.leftMargin: 40 - font.pixelSize: 17 - color: theme.color4 - text: qsTr("Sorry, there is nothing yet...") - visible: (recentList.count == 0) - } - - ListView { - id: recentList - anchors.fill: parent - spacing: 10 - anchors.leftMargin: 25 - model: recentListData - - Component { - id: recentDelegate - Item { - anchors.left: parent.left - anchors.right: parent.right - width: parent.width - height: 36 - - MouseArea { - id: recentMouseArea - anchors.fill: parent - hoverEnabled: true - onClicked: { - guiBehind.showSendPage(mac); - emit: componentClicked(mac); - } - } - - Rectangle { - anchors.fill: parent - color: "#00000000" - visible: recentMouseArea.containsMouse; - Rectangle { - anchors.right: parent.right - anchors.top: parent.top - anchors.bottom: parent.bottom - width: 5 - color: theme.color3 - } - } - - Rectangle { - id: fileImage - anchors.verticalCenter: parent.verticalCenter - width: 32 - height: 32 - color: theme.color2 - Image { - source: typeIcon - width: 32 - height: 32 - } - } - SText { - id: recentNameText - anchors.top: fileImage.top - anchors.topMargin: -2 - anchors.left: fileImage.right - anchors.leftMargin: 10 - anchors.right: parent.right - anchors.rightMargin: 20 - font.pixelSize: 14 - color: theme.color4 - elide: "ElideRight" - text: sender + " " + mac - } - SText { - anchors.left: recentNameText.left - anchors.leftMargin: 0 - anchors.right: parent.right - anchors.rightMargin: 20 - anchors.bottom: fileImage.bottom - anchors.bottomMargin: -1 - font.pixelSize: 12 - elide: "ElideRight" - color: theme.color5 - text: qsTr("Recent ") + dateTime - } - } - } - - delegate: recentDelegate - } -} diff --git a/qml/dukto/RecentText.png b/qml/dukto/RecentText.png deleted file mode 100644 index 38d1d19..0000000 Binary files a/qml/dukto/RecentText.png and /dev/null differ diff --git a/qml/dukto/SBPicker.qml b/qml/dukto/SBPicker.qml deleted file mode 100644 index c24ff3f..0000000 --- a/qml/dukto/SBPicker.qml +++ /dev/null @@ -1,85 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -// Saturation/brightness picking box -import QtQuick 2.3 - -Item { - id: root - property color hueColor : "blue" - property real saturation : pickerCursor.x/width - property real brightness : 1 - pickerCursor.y/height - - signal changed() - - function setValue(sat, brigh) { - pickerCursor.x = sat * width; - pickerCursor.y = (1 - brigh) * height; - } - - // width: 126; height: 126 - clip: true - Rectangle { - anchors.fill: parent; - rotation: -90 - gradient: Gradient { - GradientStop { position: 0.0; color: "#FFFFFF" } - GradientStop { position: 1.0; color: root.hueColor } - } - border.color: "#f0f0f0" - border.width: 2 - } - Rectangle { - anchors.fill: parent - gradient: Gradient { - GradientStop { position: 1.0; color: "#FF000000" } - GradientStop { position: 0.0; color: "#00000000" } - } - } - Item { - id: pickerCursor - property int r : 8 - Rectangle { - x: -parent.r; y: -parent.r - width: parent.r*2; height: parent.r*2 - radius: parent.r - border.color: "black"; border.width: 2 - color: "transparent" - Rectangle { - anchors.fill: parent; anchors.margins: 2; - border.color: "white"; border.width: 2 - radius: width/2 - color: "transparent" - } - } - } - MouseArea { - anchors.fill: parent - function handleMouse(mouse) { - if (mouse.buttons & Qt.LeftButton) { - pickerCursor.x = Math.max(0, Math.min(width, mouse.x)); - pickerCursor.y = Math.max(0, Math.min(height, mouse.y)); - root.changed(); - } - } - onPositionChanged: handleMouse(mouse) - onPressed: handleMouse(mouse) - } -} - diff --git a/qml/dukto/SText.qml b/qml/dukto/SText.qml deleted file mode 100644 index 45af8a9..0000000 --- a/qml/dukto/SText.qml +++ /dev/null @@ -1,25 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Text { - font.family: duktofontsmall.name - color: theme.color6 -} diff --git a/qml/dukto/SettingsPage.qml b/qml/dukto/SettingsPage.qml deleted file mode 100644 index 7f0131d..0000000 --- a/qml/dukto/SettingsPage.qml +++ /dev/null @@ -1,249 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Rectangle { - id: settingsPage - color: theme.color6 - - // 控制设置界面的显示与隐藏 - property bool showSetPage: false - visible: showSetPage - - signal back() - - function controlSettingsPage() { - showSetPage = !showSetPage - } - - function refreshColor() { - - picker.setColor(theme.color2); - } - - MouseArea { - anchors.fill: parent - } - - Image { - id: backIcon - source: "BackIconDark.png" - anchors.top: parent.top - anchors.left: parent.left - anchors.topMargin: 5 - anchors.leftMargin: 5 - - MouseArea { - anchors.fill: parent -// onClicked: settingsPage.back() - onClicked: settingsPage.controlSettingsPage(); - } - } - - SmoothText { - id: boxTitle - anchors.left: backIcon.right - anchors.top: parent.top - anchors.leftMargin: 15 - anchors.topMargin: 5 - font.pixelSize: 64 - text: qsTr("Settings") -// text: "选项设置" - color: theme.color3 - } - - SText { - id: labelPath - anchors.left: parent.left - anchors.top: parent.top - anchors.leftMargin: 17 - anchors.topMargin: 70 - font.pixelSize: 16 - text: qsTr("File Receive Path") -// text: "文件保存目录:" - color: theme.color5 - } - - Rectangle { - id: textPath - anchors.left: parent.left - anchors.right: parent.right - anchors.top: labelPath.bottom - anchors.leftMargin: 17 - anchors.rightMargin: 17 - anchors.topMargin: 8 - height: 30 - color: theme.color2 - clip: true - - Image { - anchors.top: parent.top - anchors.left: parent.left - source: "PanelGradient.png" - } - - SText { - anchors.leftMargin: 5 - anchors.rightMargin: 5 - anchors.fill: parent - horizontalAlignment: "AlignLeft" - verticalAlignment: "AlignVCenter" - elide: "ElideMiddle" - font.pixelSize: 12 - text: guiBehind.currentPath - } - } - - ButtonDark { - id: buttonPath - anchors.right: parent.right - anchors.rightMargin: 17 - anchors.top: textPath.bottom - anchors.topMargin: 10 - label: qsTr("Change Path") -// label: "更改目录" - onClicked: guiBehind.changeDestinationFolder() - } - - SText { - id: labelColor - anchors.left: labelPath.left - anchors.top: buttonPath.bottom - anchors.topMargin: 40 - font.pixelSize: 16 - text: qsTr("Theme Color") -// text: "主题颜色:" - color: theme.color5 - } - - ColorPicker { - id: picker - anchors.top: labelColor.bottom - anchors.topMargin: 8 - anchors.left: labelColor.left - onChanged: { - guiBehind.changeThemeColor(colorValue); - } - } - - ColorBox { - id: cbox1 - anchors.top: labelColor.bottom - anchors.topMargin: 8 - anchors.left: picker.right - anchors.leftMargin: 20 - color: "#248B00" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox2 - anchors.top: cbox1.top - anchors.left: cbox1.right - anchors.leftMargin: 15 - color: "#A80000" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox3 - anchors.top: cbox1.top - anchors.left: cbox2.right - anchors.leftMargin: 15 - color: "#3A6CBC" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox4 - anchors.top: cbox1.bottom - anchors.topMargin: 15 - anchors.left: cbox1.left - color: "#2e3436" // "#704214" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox5 - anchors.left: cbox4.right - anchors.top: cbox4.top - anchors.leftMargin: 15 - color: "#B77994" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox6 - anchors.top: cbox4.top - anchors.left: cbox5.right - anchors.leftMargin: 15 - color: "#5B2F42" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox7 - anchors.top: cbox4.bottom - anchors.topMargin: 15 - anchors.left: cbox4.left - color: "#353B56" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox8 - anchors.top: cbox7.top - anchors.left: cbox7.right - anchors.leftMargin: 15 - color: "#FB8504" - onClicked: picker.setColor(color) - } - - ColorBox { - id: cbox9 - anchors.top: cbox7.top - anchors.left: cbox8.right - anchors.leftMargin: 15 - color: "#6D0D71" - onClicked: picker.setColor(color) - } - - SText { - id: labelGuide - anchors.left: labelPath.left - anchors.top: cbox9.bottom - anchors.topMargin: 40 - font.pixelSize: 16 - text: qsTr("User Guide") -// text: "用户手册:" - color: theme.color5 - } - - ButtonDark { - id: buttonGuide - anchors.right: parent.right - anchors.rightMargin: 17 - anchors.top: labelGuide.bottom - anchors.topMargin: 10 - label: qsTr("View Guide") -// label: "查看手册" - onClicked: guiBehind.viewUserGuide() - } -} diff --git a/qml/dukto/ShowIpIcon - Copia.png b/qml/dukto/ShowIpIcon - Copia.png deleted file mode 100644 index bb8d3c8..0000000 Binary files a/qml/dukto/ShowIpIcon - Copia.png and /dev/null differ diff --git a/qml/dukto/ShowIpIcon.png b/qml/dukto/ShowIpIcon.png deleted file mode 100644 index e150779..0000000 Binary files a/qml/dukto/ShowIpIcon.png and /dev/null differ diff --git a/qml/dukto/SmartphoneLogo.png b/qml/dukto/SmartphoneLogo.png deleted file mode 100644 index b0d321d..0000000 Binary files a/qml/dukto/SmartphoneLogo.png and /dev/null differ diff --git a/qml/dukto/SmoothText.qml b/qml/dukto/SmoothText.qml deleted file mode 100644 index 2b94b65..0000000 --- a/qml/dukto/SmoothText.qml +++ /dev/null @@ -1,27 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -SText { - transformOrigin: Item.TopLeft - scale: 0.5 - smooth: true - font.family: duktofont.name -} diff --git a/qml/dukto/SymbianLogo.png b/qml/dukto/SymbianLogo.png deleted file mode 100644 index ffa72ba..0000000 Binary files a/qml/dukto/SymbianLogo.png and /dev/null differ diff --git a/qml/dukto/TabBar.qml b/qml/dukto/TabBar.qml deleted file mode 100644 index d42bc90..0000000 --- a/qml/dukto/TabBar.qml +++ /dev/null @@ -1,151 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Item { - id: tabBar - height: 65 - state: "buddies" - - signal clicked(string tab) - - Item { - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - - SmoothText { - id: buddyText - x: 20 - y: 10 - font.pixelSize: 72 - text: qsTr("Buddy") -// text: "好 友" - color: buddyTextMouseArea.containsMouse ? theme.color3 : theme.color7 - scale: 0.5 - - MouseArea { - id: buddyTextMouseArea - anchors.fill: parent - hoverEnabled: true - onClicked: { - tabBar.state = "buddies"; - tabBar.clicked("buddies"); - } - } - } - - SmoothText { - id: recentText - x: 125 - y: 10 - font.pixelSize: 72 - text: qsTr("Recent") -// text: "最 近" - color: recentTextMouseArea.containsMouse ? theme.color3 : theme.color7 - scale: 0.5 - - MouseArea { - id: recentTextMouseArea - anchors.fill: parent; - hoverEnabled: true; - onClicked: { - tabBar.state = "recent"; - tabBar.clicked("recent"); - } - } - } - - SmoothText { - id: aboutText - x: 230 - y: 10 - font.pixelSize: 72 - color: aboutTextMouseArea.containsMouse ? theme.color3 : theme.color7 - text: qsTr("About") -// text: "关 于" - MouseArea { - id: aboutTextMouseArea - anchors.fill: parent - hoverEnabled: true - onClicked: { - tabBar.state = "about"; - tabBar.clicked("about"); - } - } - } - } - - states: [ - State { - name: "buddies" - - PropertyChanges { - target: buddyText - color: theme.color2 // "#000000" - } - }, - State { - name: "recent" - - PropertyChanges { - target: buddyText - x: 10 - } - - PropertyChanges { - target: recentText - x: 120 - color: theme.color2 // "#000000" - } - - PropertyChanges { - target: aboutText - x: 230 - } - }, - State { - name: "about" - - PropertyChanges { - target: buddyText - x: 10 - } - - PropertyChanges { - target: recentText - x: 115 - } - - PropertyChanges { - target: aboutText - x: 220 - color: theme.color2 // "#000000" - } - } - ] - - transitions: [ - Transition { - NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuart; duration: 1000 } - ColorAnimation { duration: 300 } - } - ] -} diff --git a/qml/dukto/TileGradient.png b/qml/dukto/TileGradient.png deleted file mode 100644 index 87eaaaa..0000000 Binary files a/qml/dukto/TileGradient.png and /dev/null differ diff --git a/qml/dukto/ToolBar.qml b/qml/dukto/ToolBar.qml deleted file mode 100644 index 5b9d740..0000000 --- a/qml/dukto/ToolBar.qml +++ /dev/null @@ -1,172 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -import QtQuick 2.3 - -Item { - id: toolBar - height: 71 - anchors.bottomMargin: -18 - state: "WithoutLabels" - - signal clicked(string command) - - Behavior on anchors.bottomMargin { NumberAnimation { duration: 200; easing.type: "OutCubic" } } - - Image { - source: "BottomShadow.png" - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - fillMode: Image.TileHorizontally - } - - Rectangle { - y: 3 - anchors.left: parent.left - anchors.right: parent.right - height: 68 - color: theme.color2 - - Image { - anchors.top: parent.top - anchors.left: parent.left - source: "PanelGradient.png" - } - - Image { - id: openFolderIcon - anchors.top: parent.top - anchors.topMargin: 5 - anchors.right: showIpIcon.left - anchors.rightMargin: 40 - source: "OpenFolderIcon.png" - - MouseArea { - anchors.fill: parent - onClicked: guiBehind.openDestinationFolder(); - } - } - - SText { - anchors.top: openFolderIcon.bottom - anchors.topMargin: 3 - anchors.horizontalCenter: openFolderIcon.horizontalCenter - text: qsTr("Received Files") -// text: "已接收文件" - font.pixelSize: 12 - horizontalAlignment: Text.AlignHCenter - width: 1 - } - - Image { - id: showIpIcon - anchors.top: parent.top - anchors.topMargin: 5 - anchors.horizontalCenter: parent.horizontalCenter - source: "ShowIpIcon.png" - - MouseArea { - anchors.fill: parent - onClicked: { - guiBehind.refreshIpList(); - toolBar.clicked("ip"); - } - } - } - - SText { - anchors.top: showIpIcon.bottom - anchors.topMargin: 3 - anchors.horizontalCenter: showIpIcon.horizontalCenter - text: qsTr("My IP Addr") -// text: "我的IP地址" - font.pixelSize: 12 - horizontalAlignment: Text.AlignHCenter - width: 1 - } - - Image { - id: configIcon - anchors.top: parent.top - anchors.topMargin: 5 - anchors.left: showIpIcon.right - anchors.leftMargin: 40 - source: "ConfigIcon.png" - - MouseArea { - anchors.fill: parent - onClicked: toolBar.clicked("settings") - } - } - - SText { - anchors.top: configIcon.bottom - anchors.topMargin: 3 - anchors.horizontalCenter: configIcon.horizontalCenter - text: qsTr("Settings") -// text: "选项设置" - font.pixelSize: 12 - horizontalAlignment: Text.AlignHCenter - width: 1 - } - - Image { - id: moreIcon - anchors.top: parent.top - anchors.topMargin: 4 - anchors.right: parent.right - anchors.rightMargin: 12 - source: "MoreIcon.png" - } - - MouseArea { - anchors.top: parent.top - anchors.bottom: parent.bottom - anchors.left: moreIcon.left - anchors.right: parent.right - - onClicked: { - if (toolBar.state == "WithoutLabels") - toolBar.state = "WithLabels"; - else - toolBar.state = "WithoutLabels"; - } - } - } - - states: [ - State { - name: "WithoutLabels" - - PropertyChanges { - target: toolBar - anchors.bottomMargin: -18 - } - }, - State { - name: "WithLabels" - - PropertyChanges { - target: toolBar - anchors.bottomMargin: 0 - } - } - ] -} diff --git a/qml/dukto/TopShadow.png b/qml/dukto/TopShadow.png deleted file mode 100644 index bbf143b..0000000 Binary files a/qml/dukto/TopShadow.png and /dev/null differ diff --git a/qml/dukto/UnknownLogo.png b/qml/dukto/UnknownLogo.png deleted file mode 100644 index 310e28b..0000000 Binary files a/qml/dukto/UnknownLogo.png and /dev/null differ diff --git a/qml/dukto/WindowsLogo.png b/qml/dukto/WindowsLogo.png deleted file mode 100644 index ca3a93e..0000000 Binary files a/qml/dukto/WindowsLogo.png and /dev/null differ diff --git a/qml/dukto/WindowsPhoneLogo.png b/qml/dukto/WindowsPhoneLogo.png deleted file mode 100644 index 1415ddf..0000000 Binary files a/qml/dukto/WindowsPhoneLogo.png and /dev/null differ diff --git a/qml/kylin-ipmsg-128.png b/qml/kylin-ipmsg-128.png deleted file mode 100644 index e5772d0..0000000 Binary files a/qml/kylin-ipmsg-128.png and /dev/null differ diff --git a/qml/kylin-ipmsg-32.png b/qml/kylin-ipmsg-32.png deleted file mode 100644 index 3f8700e..0000000 Binary files a/qml/kylin-ipmsg-32.png and /dev/null differ diff --git a/qml/kylin-ipmsg-c.png b/qml/kylin-ipmsg-c.png deleted file mode 100644 index 7fa0af0..0000000 Binary files a/qml/kylin-ipmsg-c.png and /dev/null differ diff --git a/qml/kylin-ipmsg.png b/qml/kylin-ipmsg.png deleted file mode 100644 index 7fa0af0..0000000 Binary files a/qml/kylin-ipmsg.png and /dev/null differ diff --git a/qml/kylin-ipmsg_bo_CN.ts b/qml/kylin-ipmsg_bo_CN.ts deleted file mode 100644 index 64cf1b4..0000000 --- a/qml/kylin-ipmsg_bo_CN.ts +++ /dev/null @@ -1,170 +0,0 @@ - - - - - AboutPage - - - Kylin Ipmsg - ཆི་ལིན་འཕྲིན་སྐྱེལ། - - - - Provide text chat and file transfer function with no server. - མཉེན་ཆས་འདིས་ཁྱབ་ཆུང་དྲ་བའི་ནང་རོལ་གྱི་ཡི་གེའི་གླེང་མོལ་དང་ཡིག་ཆ་སྐྱེལ་འདྲེན་བྱེད་པའི་ནུས་པ་འདོན་སྤྲོད་བྱས་རྐྱེན་ཞབས་ཞུ་ཆས་མི་དགོས། - - - - Mult person concurrency. - མི་མང་པོས་དུས་མཉམ་དུ་སྤྱད་ཆོག་པ་དང་སྐུར་ལེན་མཉམ་བགྲོད་བྱ་ཆོག - - - - The UI resources comes from Dukto - འཆར་ངོས་རྒྱུ་ཆ་ནི་ཨང་རྗེན་མཉེན་ཆསDuktoལས་བྱུང་བ་ཡིན། - - - - ChatWidget - - - Kylin Ipmsg - ཆི་ལིན་འཕྲིན་སྐྱེལ། - - - - Send Text (Enter) - འཕྲིན་ཐུང་སྐུར།(Enter) - - - - Send Files - ཡིག་ཆ་སྐུར་བ། - - - - Send Dir - ཡིག་ཁུག་སྐུར་བ། - - - - Chat Widget - འཕྲིན་ཐུང་འཆར་ངོས། - - - - Sending files... - ཡིག་ཆ་སྐུར་བའི་སྒང་། - - - - Cancel - དོར་བ། - - - - Receiving files... - ཡིག་ཆ་དང་ལེན་བྱེད་སྒང་། - - - - Change nickname - ཟུར་མཆན་བཟོ་བཅོས། - - - - Confirm change - བཟོ་བཅོས་ངོས་ལེན། - - - - IpPage - - - Your IP Address - ཁྱེད་ཀྱིIPས་གནས - - - - RecentPage - - - Sorry, there is nothing yet... - དགོངས་དག ཁྱེད་ལ་འཕྲིན་ཐུང་གང་ཡང་འབྱོར་མ་སོང་། - - - - Recent - ཉེ་ལམ་གླེང་མོལ། - - - - SettingsPage - - - Settings - འདེམས་བྱང་སྒྲིག་འགོད། - - - - File Receive Path - ཡིག་ཆ་ཉར་ཚགས་དཀར་ཆག - - - - Change Path - དཀར་ཆག་བཅོས་སྒྱུར། - - - - Theme Color - བརྗོད་དོན་ཁ་མདོག - - - - User Guide - བཀོལ་མཁན་ལག་དེབ། - - - - View Guide - ལྟ་བཤེར་ལག་དེབ། - - - - TabBar - - - Buddy - གྲོགས་མཆེད། - - - - Recent - ཉེ་ཆར། - - - - About - འབྲེལ་ཡོད། - - - - ToolBar - - - Received Files - ཡིག་ཆ་དང་ལེན་བྱས། - - - - My IP Addr - ངའི་IPས་གནས། - - - - Settings - སྒྲིག་འགོད། - - - diff --git a/qml/kylin-ipmsg_zh_CN.qm b/qml/kylin-ipmsg_zh_CN.qm deleted file mode 100644 index 3329cf5..0000000 Binary files a/qml/kylin-ipmsg_zh_CN.qm and /dev/null differ diff --git a/qml/qt_zh_CN.qm b/qml/qt_zh_CN.qm deleted file mode 100644 index 766f1d2..0000000 Binary files a/qml/qt_zh_CN.qm and /dev/null differ diff --git a/qmlapplicationviewer/qmlapplicationviewer.cpp b/qmlapplicationviewer/qmlapplicationviewer.cpp deleted file mode 100644 index acaa875..0000000 --- a/qmlapplicationviewer/qmlapplicationviewer.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "qmlapplicationviewer.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include // MEEGO_EDITION_HARMATTAN - -#ifdef HARMATTAN_BOOSTER -#include -#endif - -/* -* qml application viewer private param and functions -*/ -class QmlApplicationViewerPrivate -{ - QmlApplicationViewerPrivate(QQuickView *view_) : view(view_) {} - QString mainQmlFile; - QQuickView *view; - friend class QmlApplicationViewer; - static QString adjustPath(const QString &path); -}; - -/* -* Summary: adjust the path -* Parameters: -* path: path before adjust -* Return : path after adjust. -*/ -QString QmlApplicationViewerPrivate::adjustPath(const QString &path) -{ -#ifdef Q_OS_MAC - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("%1/../Resources/%2") - .arg(QCoreApplication::applicationDirPath(), path); -#elif defined(Q_OS_QNX) - if (!QDir::isAbsolutePath(path)) - return QString::fromLatin1("app/native/%1").arg(path); -#elif !defined(Q_OS_ANDROID) - QString pathInInstallDir = - QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; - pathInInstallDir = - QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; -#endif - return path; -} - -QmlApplicationViewer::QmlApplicationViewer(QWindow *parent) - : QQuickView(parent) - , d(new QmlApplicationViewerPrivate(this)) -{ - connect(engine(), SIGNAL(quit()),QCoreApplication::instance(), SLOT(quit())); - setResizeMode(QQuickView::SizeRootObjectToView); -} - -QmlApplicationViewer::QmlApplicationViewer(QQuickView *view, QWindow *parent) - : QQuickView(parent) - , d(new QmlApplicationViewerPrivate(view)) -{ - connect(view->engine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit())); - view->setResizeMode(QQuickView::SizeRootObjectToView); -} - -QmlApplicationViewer::~QmlApplicationViewer() -{ - delete d; -} - -/* -* Summary: creater. -*/ -QmlApplicationViewer *QmlApplicationViewer::create() -{ - return new QmlApplicationViewer(); -} - -/* -* Summary: set main qml file -* Parameters: -* file: qml file path -*/ -void QmlApplicationViewer::setMainQmlFile(const QString &file) -{ -// d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file); - d->mainQmlFile = d->adjustPath(file); -#ifdef Q_OS_ANDROID - setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); -#else - setSource(QUrl::fromLocalFile(d->mainQmlFile)); -#endif -} - -/* -* Summary: add import path -* Parameters: -* file: qml file path -*/ -void QmlApplicationViewer::addImportPath(const QString &path) -{ - // engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path)); - d->view->engine()->addImportPath(d->adjustPath(path)); -} - -/* -* Summary: set orientation -* Parameters: -* orientation: target orientation -*/ -void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) -{ -#if QT_VERSION < 0x050000 - Qt::WidgetAttribute attribute; - switch (orientation) { -#if QT_VERSION < 0x040702 - // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes - case ScreenOrientationLockPortrait: - attribute = static_cast(128); - break; - case ScreenOrientationLockLandscape: - attribute = static_cast(129); - break; - default: - case ScreenOrientationAuto: - attribute = static_cast(130); - break; -#else // QT_VERSION < 0x040702 - case ScreenOrientationLockPortrait: - attribute = Qt::WA_LockPortraitOrientation; - break; - case ScreenOrientationLockLandscape: - attribute = Qt::WA_LockLandscapeOrientation; - break; - default: - case ScreenOrientationAuto: - attribute = Qt::WA_AutoOrientation; - break; -#endif // QT_VERSION < 0x040702 - }; - setAttribute(attribute, true); -#else // QT_VERSION < 0x050000 - Q_UNUSED(orientation) -#endif // QT_VERSION < 0x050000 -} - -/* -* Summary: show qml widget expanded -* -*/ -void QmlApplicationViewer::showExpanded() -{ -//#if defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) -#if defined(MEEGO_EDITION_HARMATTAN) || defined(Q_OS_SIMULATOR) - showFullScreen(); -#elif defined(Q_WS_MAEMO_5) || defined(Q_OS_QNX) - showMaximized(); -#else - show(); -#endif -} - -/* -* Summary: create application -* Parameters: -* argc: main argc -* argv: main argv -*/ -//QApplication *createApplication(int &argc, char **argv) -QGuiApplication *createApplication(int &argc, char **argv) -{ -#ifdef HARMATTAN_BOOSTER - return MDeclarativeCache::qApplication(argc, argv); -#else - return new QGuiApplication(argc, argv); -#endif -} diff --git a/qmlapplicationviewer/qmlapplicationviewer.h b/qmlapplicationviewer/qmlapplicationviewer.h deleted file mode 100644 index 38c7219..0000000 --- a/qmlapplicationviewer/qmlapplicationviewer.h +++ /dev/null @@ -1,59 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef QMLAPPLICATIONVIEWER_H -#define QMLAPPLICATIONVIEWER_H -#include - -#include -#include -#include - -class QmlApplicationViewer : public QQuickView -{ - Q_OBJECT - -public: - enum ScreenOrientation { - ScreenOrientationLockPortrait, - ScreenOrientationLockLandscape, - ScreenOrientationAuto - }; - - explicit QmlApplicationViewer(QWindow *parent = 0); - virtual ~QmlApplicationViewer(); - - static QmlApplicationViewer *create(); - - void setMainQmlFile(const QString &file); - void addImportPath(const QString &path); - - // Note that this will only have an effect on Fremantle. - void setOrientation(ScreenOrientation orientation); - - void showExpanded(); - -private: - explicit QmlApplicationViewer(QQuickView *view, QWindow *parent); - class QmlApplicationViewerPrivate *d; -}; - -QGuiApplication *createApplication(int &argc, char **argv); - -#endif // QMLAPPLICATIONVIEWER_H diff --git a/qmlapplicationviewer/qmlapplicationviewer.pri b/qmlapplicationviewer/qmlapplicationviewer.pri deleted file mode 100644 index f4f5095..0000000 --- a/qmlapplicationviewer/qmlapplicationviewer.pri +++ /dev/null @@ -1,103 +0,0 @@ -# DUKTO - A simple, fast and multi-platform file transfer tool for LAN users -# Copyright (C) 2011 Emanuele Colombo -# 2020 KylinSoft Co., Ltd. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -QT += quick qml - -SOURCES += $$PWD/qmlapplicationviewer.cpp -HEADERS += $$PWD/qmlapplicationviewer.h -INCLUDEPATH += $$PWD - -contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) { - DEFINES += HARMATTAN_BOOSTER -} - -defineTest(qtcAddDeployment) { -for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - greaterThan(QT_MAJOR_VERSION, 4) { - itemsources = $${item}.files - } else { - itemsources = $${item}.sources - } - $$itemsources = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath= $$eval($${deploymentfolder}.target) - export($$itemsources) - export($$itempath) - DEPLOYMENT += $$item -} - -MAINPROFILEPWD = $$PWD - -copyCommand = -for(deploymentfolder, DEPLOYMENTFOLDERS) { - source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) - source = $$replace(source, \\\\, /) - macx { - target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) - } else { - target = $$OUT_PWD/$$eval($${deploymentfolder}.target) - } - target = $$replace(target, \\\\, /) - sourcePathSegments = $$split(source, /) - targetFullPath = $$target/$$last(sourcePathSegments) - targetFullPath ~= s,/\\.?/,/, - !isEqual(source,$$targetFullPath) { - !isEmpty(copyCommand):copyCommand += && - copyCommand += $(MKDIR) \"$$target\" - copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" - } -} -!isEmpty(copyCommand) { - copyCommand = @echo Copying application data... && $$copyCommand - copydeploymentfolders.commands = $$copyCommand - first.depends = $(first) copydeploymentfolders - export(first.depends) - export(copydeploymentfolders.commands) - QMAKE_EXTRA_TARGETS += first copydeploymentfolders -} -installPrefix = /opt/$${TARGET} -for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - itemfiles = $${item}.files - $$itemfiles = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) - export($$itemfiles) - export($$itempath) - INSTALLS += $$item -} - -!isEmpty(desktopfile.path) { - export(icon.files) - export(icon.path) - export(desktopfile.files) - export(desktopfile.path) - INSTALLS += icon desktopfile -} - -target.path = $${installPrefix}/bin -export(target.path) -INSTALLS += target - -export (ICON) -export (INSTALLS) -export (DEPLOYMENT) -export (LIBS) -export (QMAKE_EXTRA_TARGETS) -} diff --git a/qtsingleapplication/qtlocalpeer.cpp b/qtsingleapplication/qtlocalpeer.cpp deleted file mode 100644 index 9fca1be..0000000 --- a/qtsingleapplication/qtlocalpeer.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - - -#include "qtlocalpeer.h" -#include -#include -#include - -#if defined(Q_OS_WIN) -#include -#include -typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*); -static PProcessIdToSessionId pProcessIdToSessionId = 0; -#endif -#if defined(Q_OS_UNIX) -#include -#include -#include -#endif - -namespace QtLP_Private { -#include "qtlockedfile.cpp" -#if defined(Q_OS_WIN) -#include "qtlockedfile_win.cpp" -#else -#include "qtlockedfile_unix.cpp" -#endif -} - -const char* QtLocalPeer::ack = "ack"; - -/* -* Summary: qt local peer -* Parameters:res) -* parent: parent widget -* appid: appid -* Return : . -*/ -QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) - : QObject(parent), id(appId) -{ - QString prefix = id; - if (id.isEmpty()) { - id = QCoreApplication::applicationFilePath(); -#if defined(Q_OS_WIN) - id = id.toLower(); -#endif - prefix = id.section(QLatin1Char('/'), -1); - } - prefix.remove(QRegExp("[^a-zA-Z]")); - prefix.truncate(6); - - QByteArray idc = id.toUtf8(); - quint16 idNum = qChecksum(idc.constData(), idc.size()); - socketName = QLatin1String("qtsingleapp-") + prefix - + QLatin1Char('-') + QString::number(idNum, 16); - -#if defined(Q_OS_WIN) - if (!pProcessIdToSessionId) { - QLibrary lib("kernel32"); - pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); - } - if (pProcessIdToSessionId) { - DWORD sessionId = 0; - pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); - socketName += QLatin1Char('-') + QString::number(sessionId, 16); - } -#else - socketName += QLatin1Char('-') + QString::number(::getuid(), 16); -#endif - - server = new QLocalServer(this); - QString lockName = QDir(QDir::tempPath()).absolutePath() - + QLatin1Char('/') + socketName - + QLatin1String("-lockfile"); - lockFile.setFileName(lockName); - lockFile.open(QIODevice::ReadWrite); -} - - -/* -* Summary: check is clinet -* Parameters: -* -* Return : . -*/ -bool QtLocalPeer::isClient() -{ - if (lockFile.isLocked()) - return false; - - if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) - return true; - - bool res = server->listen(socketName); -#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) - // ### Workaround - if (!res && server->serverError() == QAbstractSocket::AddressInUseError) { - QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName); - res = server->listen(socketName); - } -#endif - if (!res) - qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); - QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); - return false; -} - -/* -* Summary:send a message -* Parameters: -* message: msg -* timeout: timeout -* Return : -*/ -bool QtLocalPeer::sendMessage(const QString &message, int timeout) -{ - if (!isClient()) - return false; - - QLocalSocket socket; - bool connOk = false; - for(int i = 0; i < 2; i++) { - // Try twice, in case the other instance is just starting up - socket.connectToServer(socketName); - connOk = socket.waitForConnected(timeout/2); - if (connOk || i) - break; - int ms = 250; -#if defined(Q_OS_WIN) - Sleep(DWORD(ms)); -#else - struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; - nanosleep(&ts, NULL); -#endif - } - if (!connOk) - return false; - - QByteArray uMsg(message.toUtf8()); - QDataStream ds(&socket); - ds.writeBytes(uMsg.constData(), uMsg.size()); - bool res = socket.waitForBytesWritten(timeout); - res &= socket.waitForReadyRead(timeout); // wait for ack - res &= (socket.read(qstrlen(ack)) == ack); - return res; -} - -/* -* Summary: receive connection -* Parameters: -* -* Return : -*/ -void QtLocalPeer::receiveConnection() -{ - qDebug() << "receiveConnection"; - QLocalSocket* socket = server->nextPendingConnection(); - if (!socket) - return; - - while (socket->bytesAvailable() < (int)sizeof(quint32)) - socket->waitForReadyRead(); - QDataStream ds(socket); - QByteArray uMsg; - quint32 remaining; - ds >> remaining; - uMsg.resize(remaining); - int got = 0; - char* uMsgBuf = uMsg.data(); - do { - got = ds.readRawData(uMsgBuf, remaining); - remaining -= got; - uMsgBuf += got; - } while (remaining && got >= 0 && socket->waitForReadyRead(2000)); - if (got < 0) { - qWarning() << "QtLocalPeer: Message reception failed" << socket->errorString(); -// delete socket; - socket->deleteLater(); - return; - } - QString message(QString::fromUtf8(uMsg)); - socket->write(ack, qstrlen(ack)); - socket->waitForBytesWritten(1000); -// delete socket; - socket->deleteLater(); - emit messageReceived(message); //### (might take a long time to return) -} diff --git a/qtsingleapplication/qtlocalpeer.h b/qtsingleapplication/qtlocalpeer.h deleted file mode 100644 index 4735ae7..0000000 --- a/qtsingleapplication/qtlocalpeer.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#ifndef QTLOCALPEER_H -#define QTLOCALPEER_H - -#include -#include -#include - -#include "qtlockedfile.h" - -//namespace QtLP_Private { -//#include "qtlockedfile.h" -//} - -class QtLocalPeer : public QObject -{ - Q_OBJECT - -public: - QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); - bool isClient(); - bool sendMessage(const QString &message, int timeout); - QString applicationId() const - { return id; } - -Q_SIGNALS: - void messageReceived(const QString &message); - -protected Q_SLOTS: - void receiveConnection(); - -protected: - QString id; - QString socketName; - QLocalServer* server; - QtLP_Private::QtLockedFile lockFile; - -private: - static const char* ack; -}; - -#endif // QTLOCALPEER_H diff --git a/qtsingleapplication/qtlockedfile.cpp b/qtsingleapplication/qtlockedfile.cpp deleted file mode 100644 index fb30521..0000000 --- a/qtsingleapplication/qtlockedfile.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#include "qtlockedfile.h" - -/*! - \class QtLockedFile - - \brief The QtLockedFile class extends QFile with advisory locking - functions. - - A file may be locked in read or write mode. Multiple instances of - \e QtLockedFile, created in multiple processes running on the same - machine, may have a file locked in read mode. Exactly one instance - may have it locked in write mode. A read and a write lock cannot - exist simultaneously on the same file. - - The file locks are advisory. This means that nothing prevents - another process from manipulating a locked file using QFile or - file system functions offered by the OS. Serialization is only - guaranteed if all processes that access the file use - QLockedFile. Also, while holding a lock on a file, a process - must not open the same file again (through any API), or locks - can be unexpectedly lost. - - The lock provided by an instance of \e QtLockedFile is released - whenever the program terminates. This is true even when the - program crashes and no destructors are called. -*/ - -/*! \enum QtLockedFile::LockMode - - This enum describes the available lock modes. - - \value ReadLock A read lock. - \value WriteLock A write lock. - \value NoLock Neither a read lock nor a write lock. -*/ - -/*! - Constructs an unlocked \e QtLockedFile object. This constructor - behaves in the same way as \e QFile::QFile(). - - \sa QFile::QFile() -*/ -QtLockedFile::QtLockedFile() - : QFile() -{ -#ifdef Q_OS_WIN - wmutex = 0; - rmutex = 0; -#endif - m_lock_mode = NoLock; -} - -/*! - Constructs an unlocked QtLockedFile object with file \a name. This - constructor behaves in the same way as \e QFile::QFile(const - QString&). - - \sa QFile::QFile() -*/ -QtLockedFile::QtLockedFile(const QString &name) - : QFile(name) -{ -#ifdef Q_OS_WIN - wmutex = 0; - rmutex = 0; -#endif - m_lock_mode = NoLock; -} - -/*! - Opens the file in OpenMode \a mode. - - This is identical to QFile::open(), with the one exception that the - Truncate mode flag is disallowed. Truncation would conflict with the - advisory file locking, since the file would be modified before the - write lock is obtained. If truncation is required, use resize(0) - after obtaining the write lock. - - Returns true if successful; otherwise false. - - \sa QFile::open(), QFile::resize() -*/ -bool QtLockedFile::open(OpenMode mode) -{ - if (mode & QIODevice::Truncate) { - qWarning("QtLockedFile::open(): Truncate mode not allowed."); - return false; - } - return QFile::open(mode); -} - -/*! - Returns \e true if this object has a in read or write lock; - otherwise returns \e false. - - \sa lockMode() -*/ -bool QtLockedFile::isLocked() const -{ - return m_lock_mode != NoLock; -} - -/*! - Returns the type of lock currently held by this object, or \e - QtLockedFile::NoLock. - - \sa isLocked() -*/ -QtLockedFile::LockMode QtLockedFile::lockMode() const -{ - return m_lock_mode; -} - -/*! - \fn bool QtLockedFile::lock(LockMode mode, bool block = true) - - Obtains a lock of type \a mode. The file must be opened before it - can be locked. - - If \a block is true, this function will block until the lock is - aquired. If \a block is false, this function returns \e false - immediately if the lock cannot be aquired. - - If this object already has a lock of type \a mode, this function - returns \e true immediately. If this object has a lock of a - different type than \a mode, the lock is first released and then a - new lock is obtained. - - This function returns \e true if, after it executes, the file is - locked by this object, and \e false otherwise. - - \sa unlock(), isLocked(), lockMode() -*/ - -/*! - \fn bool QtLockedFile::unlock() - - Releases a lock. - - If the object has no lock, this function returns immediately. - - This function returns \e true if, after it executes, the file is - not locked by this object, and \e false otherwise. - - \sa lock(), isLocked(), lockMode() -*/ - -/*! - \fn QtLockedFile::~QtLockedFile() - - Destroys the \e QtLockedFile object. If any locks were held, they - are released. -*/ diff --git a/qtsingleapplication/qtlockedfile.h b/qtsingleapplication/qtlockedfile.h deleted file mode 100644 index bbd91ef..0000000 --- a/qtsingleapplication/qtlockedfile.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#ifndef QTLOCKEDFILE_H -#define QTLOCKEDFILE_H - -#include -#ifdef Q_OS_WIN -#include -#endif - -#if defined(Q_OS_WIN) -# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT) -# define QT_QTLOCKEDFILE_EXPORT -# elif defined(QT_QTLOCKEDFILE_IMPORT) -# if defined(QT_QTLOCKEDFILE_EXPORT) -# undef QT_QTLOCKEDFILE_EXPORT -# endif -# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport) -# elif defined(QT_QTLOCKEDFILE_EXPORT) -# undef QT_QTLOCKEDFILE_EXPORT -# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport) -# endif -#else -# define QT_QTLOCKEDFILE_EXPORT -#endif - -namespace QtLP_Private { - -class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile -{ -public: - enum LockMode { NoLock = 0, ReadLock, WriteLock }; - - QtLockedFile(); - QtLockedFile(const QString &name); - ~QtLockedFile(); - - bool open(OpenMode mode) override; - - bool lock(LockMode mode, bool block = true); - bool unlock(); - bool isLocked() const; - LockMode lockMode() const; - -private: -#ifdef Q_OS_WIN - Qt::HANDLE wmutex; - Qt::HANDLE rmutex; - QVector rmutexes; - QString mutexname; - - Qt::HANDLE getMutexHandle(int idx, bool doCreate); - bool waitMutex(Qt::HANDLE mutex, bool doBlock); - -#endif - LockMode m_lock_mode; -}; -} - -#endif diff --git a/qtsingleapplication/qtlockedfile_unix.cpp b/qtsingleapplication/qtlockedfile_unix.cpp deleted file mode 100644 index fa70711..0000000 --- a/qtsingleapplication/qtlockedfile_unix.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#include -#include -#include -#include - -#include "qtlockedfile.h" - -bool QtLockedFile::lock(LockMode mode, bool block) -{ - if (!isOpen()) { - qWarning("QtLockedFile::lock(): file is not opened"); - return false; - } - - if (mode == NoLock) - return unlock(); - - if (mode == m_lock_mode) - return true; - - if (m_lock_mode != NoLock) - unlock(); - - struct flock fl; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; - fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; - int cmd = block ? F_SETLKW : F_SETLK; - int ret = fcntl(handle(), cmd, &fl); - - if (ret == -1) { - if (errno != EINTR && errno != EAGAIN) - qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); - return false; - } - - - m_lock_mode = mode; - return true; -} - - -bool QtLockedFile::unlock() -{ - if (!isOpen()) { - qWarning("QtLockedFile::unlock(): file is not opened"); - return false; - } - - if (!isLocked()) - return true; - - struct flock fl; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; - fl.l_type = F_UNLCK; - int ret = fcntl(handle(), F_SETLKW, &fl); - - if (ret == -1) { - qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); - return false; - } - - m_lock_mode = NoLock; - return true; -} - -QtLockedFile::~QtLockedFile() -{ - if (isOpen()) - unlock(); -} - diff --git a/qtsingleapplication/qtlockedfile_win.cpp b/qtsingleapplication/qtlockedfile_win.cpp deleted file mode 100644 index 31ce21e..0000000 --- a/qtsingleapplication/qtlockedfile_win.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#include "qtlockedfile.h" -#include -#include - -#define MUTEX_PREFIX "QtLockedFile mutex " -// Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS -#define MAX_READERS MAXIMUM_WAIT_OBJECTS - -Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) -{ - if (mutexname.isEmpty()) { - QFileInfo fi(*this); - mutexname = QString::fromLatin1(MUTEX_PREFIX) - + fi.absoluteFilePath().toLower(); - } - QString mname(mutexname); - if (idx >= 0) - mname += QString::number(idx); - - Qt::HANDLE mutex; - if (doCreate) { - QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, - { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); - if (!mutex) { - qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); - return 0; - } - } - else { - QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, - { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); - if (!mutex) { - if (GetLastError() != ERROR_FILE_NOT_FOUND) - qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); - return 0; - } - } - return mutex; -} - -bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock) -{ - Q_ASSERT(mutex); - DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0); - switch (res) { - case WAIT_OBJECT_0: - case WAIT_ABANDONED: - return true; - break; - case WAIT_TIMEOUT: - break; - default: - qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed"); - } - return false; -} - - - -bool QtLockedFile::lock(LockMode mode, bool block) -{ - if (!isOpen()) { - qWarning("QtLockedFile::lock(): file is not opened"); - return false; - } - - if (mode == NoLock) - return unlock(); - - if (mode == m_lock_mode) - return true; - - if (m_lock_mode != NoLock) - unlock(); - - if (!wmutex && !(wmutex = getMutexHandle(-1, true))) - return false; - - if (!waitMutex(wmutex, block)) - return false; - - if (mode == ReadLock) { - int idx = 0; - for (; idx < MAX_READERS; idx++) { - rmutex = getMutexHandle(idx, false); - if (!rmutex || waitMutex(rmutex, false)) - break; - CloseHandle(rmutex); - } - bool ok = true; - if (idx >= MAX_READERS) { - qWarning("QtLockedFile::lock(): too many readers"); - rmutex = 0; - ok = false; - } - else if (!rmutex) { - rmutex = getMutexHandle(idx, true); - if (!rmutex || !waitMutex(rmutex, false)) - ok = false; - } - if (!ok && rmutex) { - CloseHandle(rmutex); - rmutex = 0; - } - ReleaseMutex(wmutex); - if (!ok) - return false; - } - else { - Q_ASSERT(rmutexes.isEmpty()); - for (int i = 0; i < MAX_READERS; i++) { - Qt::HANDLE mutex = getMutexHandle(i, false); - if (mutex) - rmutexes.append(mutex); - } - if (rmutexes.size()) { - DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), - TRUE, block ? INFINITE : 0); - if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) { - if (res != WAIT_TIMEOUT) - qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed"); - m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky - unlock(); - return false; - } - } - } - - m_lock_mode = mode; - return true; -} - -bool QtLockedFile::unlock() -{ - if (!isOpen()) { - qWarning("QtLockedFile::unlock(): file is not opened"); - return false; - } - - if (!isLocked()) - return true; - - if (m_lock_mode == ReadLock) { - ReleaseMutex(rmutex); - CloseHandle(rmutex); - rmutex = 0; - } - else { - foreach(Qt::HANDLE mutex, rmutexes) { - ReleaseMutex(mutex); - CloseHandle(mutex); - } - rmutexes.clear(); - ReleaseMutex(wmutex); - } - - m_lock_mode = QtLockedFile::NoLock; - return true; -} - -QtLockedFile::~QtLockedFile() -{ - if (isOpen()) - unlock(); - if (wmutex) - CloseHandle(wmutex); -} diff --git a/qtsingleapplication/qtsingleapplication.cpp b/qtsingleapplication/qtsingleapplication.cpp deleted file mode 100644 index b3e6acb..0000000 --- a/qtsingleapplication/qtsingleapplication.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - - -#include "qtsingleapplication.h" -#include "qtlocalpeer.h" -#include - -/*! - \class QtSingleApplication qtsingleapplication.h - \brief The QtSingleApplication class provides an API to detect and - communicate with running instances of an application. - - This class allows you to create applications where only one - instance should be running at a time. I.e., if the user tries to - launch another instance, the already running instance will be - activated instead. Another usecase is a client-server system, - where the first started instance will assume the role of server, - and the later instances will act as clients of that server. - - By default, the full path of the executable file is used to - determine whether two processes are instances of the same - application. You can also provide an explicit identifier string - that will be compared instead. - - The application should create the QtSingleApplication object early - in the startup phase, and call isRunning() or sendMessage() to - find out if another instance of this application is already - running. Startup parameters (e.g. the name of the file the user - wanted this new instance to open) can be passed to the running - instance in the sendMessage() function. - - If isRunning() or sendMessage() returns false, it means that no - other instance is running, and this instance has assumed the role - as the running instance. The application should continue with the - initialization of the application user interface before entering - the event loop with exec(), as normal. The messageReceived() - signal will be emitted when the application receives messages from - another instance of the same application. - - If isRunning() or sendMessage() returns true, another instance is - already running, and the application should terminate or enter - client mode. - - If a message is received it might be helpful to the user to raise - the application so that it becomes visible. To facilitate this, - QtSingleApplication provides the setActivationWindow() function - and the activateWindow() slot. - - Here's an example that shows how to convert an existing - application to use QtSingleApplication. It is very simple and does - not make use of all QtSingleApplication's functionality (see the - examples for that). - - \code - // Original - int main(int argc, char **argv) - { - QApplication app(argc, argv); - - MyMainWidget mmw; - - mmw.show(); - return app.exec(); - } - - // Single instance - int main(int argc, char **argv) - { - QtSingleApplication app(argc, argv); - - if (app.isRunning()) - return 0; - - MyMainWidget mmw; - - app.setActivationWindow(&mmw); - - mmw.show(); - return app.exec(); - } - \endcode - - Once this QtSingleApplication instance is destroyed(for example, - when the user quits), when the user next attempts to run the - application this instance will not, of course, be encountered. The - next instance to call isRunning() or sendMessage() will assume the - role as the new running instance. - - For console (non-GUI) applications, QtSingleCoreApplication may be - used instead of this class, to avoid the dependency on the QtGui - library. - - \sa QtSingleCoreApplication -*/ - -/* -* Summary: single system init -* Parameters: -* appid: appid -* Return : -*/ -void QtSingleApplication::sysInit(const QString &appId) -{ - actWin = 0; - peer = new QtLocalPeer(this, appId); - connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); -} - - -/*! - Creates a QtSingleApplication object. The application identifier - will be QCoreApplication::applicationFilePath(). \a argc, \a - argv, and \a GUIenabled are passed on to the QAppliation constructor. - - If you are creating a console application (i.e. setting \a - GUIenabled to false), you may consider using - QtSingleCoreApplication instead. -*/ - -QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) - : QApplication(argc, argv, GUIenabled) -{ - sysInit(); -} - - -/*! - Creates a QtSingleApplication object with the application - identifier \a appId. \a argc and \a argv are passed on to the - QAppliation constructor. -*/ - -QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) - : QApplication(argc, argv) -{ - sysInit(appId); -} - - -/*! - Creates a QtSingleApplication object. The application identifier - will be QCoreApplication::applicationFilePath(). \a argc, \a - argv, and \a type are passed on to the QAppliation constructor. -*/ -//QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) -// : QApplication(argc, argv, type) -//{ -// sysInit(); -//} - - -#if defined(Q_WS_X11) -/*! - Special constructor for X11, ref. the documentation of - QApplication's corresponding constructor. The application identifier - will be QCoreApplication::applicationFilePath(). \a dpy, \a visual, - and \a cmap are passed on to the QApplication constructor. -*/ -QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap) - : QApplication(dpy, visual, cmap) -{ - sysInit(); -} - -/*! - Special constructor for X11, ref. the documentation of - QApplication's corresponding constructor. The application identifier - will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a - argv, \a visual, and \a cmap are passed on to the QApplication - constructor. -*/ -QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) - : QApplication(dpy, argc, argv, visual, cmap) -{ - sysInit(); -} - -/*! - Special constructor for X11, ref. the documentation of - QApplication's corresponding constructor. The application identifier - will be \a appId. \a dpy, \a argc, \a - argv, \a visual, and \a cmap are passed on to the QApplication - constructor. -*/ -QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) - : QApplication(dpy, argc, argv, visual, cmap) -{ - sysInit(appId); -} -#endif - - -/*! - Returns true if another instance of this application is running; - otherwise false. - - This function does not find instances of this application that are - being run by a different user (on Windows: that are running in - another session). - - \sa sendMessage() -*/ - -/* -* Summary: check is running -* Parameters: -* -* Return : -*/ -bool QtSingleApplication::isRunning() -{ - return peer->isClient(); -} - - -/*! - Tries to send the text \a message to the currently running - instance. The QtSingleApplication object in the running instance - will emit the messageReceived() signal when it receives the - message. - - This function returns true if the message has been sent to, and - processed by, the current instance. If there is no instance - currently running, or if the running instance fails to process the - message within \a timeout milliseconds, this function return false. - - \sa isRunning(), messageReceived() -*/ -bool QtSingleApplication::sendMessage(const QString &message, int timeout) -{ - return peer->sendMessage(message, timeout); -} - - -/*! - Returns the application identifier. Two processes with the same - identifier will be regarded as instances of the same application. -*/ -QString QtSingleApplication::id() const -{ - return peer->applicationId(); -} - - -/*! - Sets the activation window of this application to \a aw. The - activation window is the widget that will be activated by - activateWindow(). This is typically the application's main window. - - If \a activateOnMessage is true (the default), the window will be - activated automatically every time a message is received, just prior - to the messageReceived() signal being emitted. - - \sa activateWindow(), messageReceived() -*/ - -void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) -{ - actWin = aw; - if (activateOnMessage) - connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); - else - disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); -} - - -/*! - Returns the applications activation window if one has been set by - calling setActivationWindow(), otherwise returns 0. - - \sa setActivationWindow() -*/ -QWidget* QtSingleApplication::activationWindow() const -{ - return actWin; -} - - -/*! - De-minimizes, raises, and activates this application's activation window. - This function does nothing if no activation window has been set. - - This is a convenience function to show the user that this - application instance has been activated when he has tried to start - another instance. - - This function should typically be called in response to the - messageReceived() signal. By default, that will happen - automatically, if an activation window has been set. - - \sa setActivationWindow(), messageReceived(), initialize() -*/ -void QtSingleApplication::activateWindow() -{ - if (actWin) { - actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized); - actWin->raise(); - actWin->activateWindow(); - } -} - - -/*! - \fn void QtSingleApplication::messageReceived(const QString& message) - - This signal is emitted when the current instance receives a \a - message from another instance of this application. - - \sa sendMessage(), setActivationWindow(), activateWindow() -*/ - - -/*! - \fn void QtSingleApplication::initialize(bool dummy = true) - - \obsolete -*/ diff --git a/qtsingleapplication/qtsingleapplication.h b/qtsingleapplication/qtsingleapplication.h deleted file mode 100644 index 6b1f9dc..0000000 --- a/qtsingleapplication/qtsingleapplication.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** This file is part of a Qt Solutions component. -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** 2020 KylinSoft Co., Ltd. -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Solutions Commercial License Agreement provided -** with the Software or, alternatively, in accordance with the terms -** contained in a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** Please note Third Party Software included with Qt Solutions may impose -** additional restrictions and it is the user's responsibility to ensure -** that they have met the licensing requirements of the GPL, LGPL, or Qt -** Solutions Commercial license and the relevant license of the Third -** Party Software they are using. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#ifndef QTSINGLEAPPLICATION_H -#define QTSINGLEAPPLICATION_H - -#include - -class QtLocalPeer; - -#if defined(Q_OS_WIN) -# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) -# define QT_QTSINGLEAPPLICATION_EXPORT -# elif defined(QT_QTSINGLEAPPLICATION_IMPORT) -# if defined(QT_QTSINGLEAPPLICATION_EXPORT) -# undef QT_QTSINGLEAPPLICATION_EXPORT -# endif -# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) -# elif defined(QT_QTSINGLEAPPLICATION_EXPORT) -# undef QT_QTSINGLEAPPLICATION_EXPORT -# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) -# endif -#else -# define QT_QTSINGLEAPPLICATION_EXPORT -#endif - - -class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication -{ - Q_OBJECT - -public: - QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); - QtSingleApplication(const QString &id, int &argc, char **argv); -// QtSingleApplication(int &argc, char **argv, Type type); -#if defined(Q_WS_X11) - QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); - QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); - QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); -#endif - - bool isRunning(); - QString id() const; - - void setActivationWindow(QWidget* aw, bool activateOnMessage = true); - QWidget* activationWindow() const; - - // Obsolete: - void initialize(bool dummy = true) - { isRunning(); Q_UNUSED(dummy) } - -public Q_SLOTS: - bool sendMessage(const QString &message, int timeout = 5000); - void activateWindow(); - - -Q_SIGNALS: - void messageReceived(const QString &message); - - -private: - void sysInit(const QString &appId = QString()); - QtLocalPeer *peer; - QWidget *actWin; -}; - -#endif // QTSINGLEAPPLICATION_H diff --git a/qtsingleapplication/qtsingleapplication.pri b/qtsingleapplication/qtsingleapplication.pri deleted file mode 100644 index 57945de..0000000 --- a/qtsingleapplication/qtsingleapplication.pri +++ /dev/null @@ -1,3 +0,0 @@ -SOURCES += $$PWD/qtsingleapplication.cpp $$PWD/qtlocalpeer.cpp -HEADERS += $$PWD/qtsingleapplication.h $$PWD/qtlocalpeer.h -INCLUDEPATH += $$PWD diff --git a/recentlistitemmodel.cpp b/recentlistitemmodel.cpp deleted file mode 100644 index 798b8ba..0000000 --- a/recentlistitemmodel.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "recentlistitemmodel.h" - - -RecentListItemModel::RecentListItemModel() : - QStandardItemModel(NULL) -{ - QHash roleNames; - roleNames[Name] = "name"; - roleNames[Value] = "value"; - roleNames[Type] = "type"; - roleNames[TypeIcon] = "typeIcon"; - roleNames[DateTime] = "dateTime"; - roleNames[Sender] = "sender"; - roleNames[Size] = "size"; - roleNames[Mac] = "mac"; - setItemRoleNames(roleNames); -} - -// 添加最近聊天记录 -/* -* Parameters: -* name: user name -* value: msg value -* type: msg type -* sender: msg sender -* size: msg size -* ip_mac: sender ip and mac address string -* Return : -*/ -void RecentListItemModel::addRecent(QString name, QString value, QString type, QString sender, qint64 size, QString ip_mac) -{ - QStandardItem* it = new QStandardItem(); - - // Format timestamp - QDateTime now = QDateTime::currentDateTime(); - QString datetime = now.toString(Qt::SystemLocaleShortDate); - - // Convert size data - QString sizeFormatted; - if (size < 1024) - sizeFormatted = QString::number(size) + " B"; - else if (size < 1048576) - sizeFormatted = QString::number(size * 1.0 / 1024, 'f', 1) + " KB"; - else - sizeFormatted = QString::number(size * 1.0 / 1048576, 'f', 1) + " MB"; - - // Icon - if (type == "text") - it->setData("RecentText.png", RecentListItemModel::TypeIcon); - else if (type == "file") - it->setData("RecentFile.png", RecentListItemModel::TypeIcon); - else - it->setData("RecentFiles.png", RecentListItemModel::TypeIcon); - - if (type == "text") - it->setData(name, RecentListItemModel::Name); - else - it->setData(name + " (" + sizeFormatted + ")", RecentListItemModel::Name); - it->setData(value, RecentListItemModel::Value); - it->setData(type, RecentListItemModel::Type); - it->setData(datetime, RecentListItemModel::DateTime); - it->setData(sender, RecentListItemModel::Sender); - it->setData(sizeFormatted, RecentListItemModel::Size); - it->setData(ip_mac, RecentListItemModel::Mac); - insertRow(0, it); -} diff --git a/recentlistitemmodel.h b/recentlistitemmodel.h deleted file mode 100644 index 29aee86..0000000 --- a/recentlistitemmodel.h +++ /dev/null @@ -1,46 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef RECENTLISTITEMMODEL_H -#define RECENTLISTITEMMODEL_H - -#include -#include - - -class RecentListItemModel : public QStandardItemModel -{ - Q_OBJECT -public: - explicit RecentListItemModel(); - void addRecent(QString name, QString value, QString type, QString sender, qint64 size, QString senderIp); - - enum RecentRoles { - Name = Qt::UserRole + 1, - Value, - Type, - TypeIcon, - DateTime, - Sender, - Size, - Mac - }; -}; - -#endif // RECENTLISTITEMMODEL_H diff --git a/kylin-ipmsg.png b/res/kylin-ipmsg.png similarity index 100% rename from kylin-ipmsg.png rename to res/kylin-ipmsg.png diff --git a/run b/run old mode 100755 new mode 100644 index a5e1ec5..d7893e0 --- a/run +++ b/run @@ -1,10 +1,9 @@ #!/bin/bash -rm .qmake.stash rm -rf build mkdir build cd build qmake .. -make -j6 +make -j8 sudo make install -./$1 +./src/kylin-messages diff --git a/settings.cpp b/settings.cpp deleted file mode 100644 index affbc36..0000000 --- a/settings.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "settings.h" -#include "platform.h" -#include "theme.h" - -#include -#include - -Settings::Settings(QObject *parent) : - QObject(parent), mSettings("kylinos.cn", "KylinIpmsg"){ -} - -// 获取当前接收文件路径 -QString Settings::currentPath() -{ - // Retrieve the last saved path (if any) - QString path = mSettings.value("DestPath", "").toString(); - - // Check if exists - if ((path != "") && (QDir(path).exists())) - return path; - - // Else return the default path for this platform - path = Platform::getDefaultPath(); - if (QDir(path).exists() == false){ - QDir qdir; - qdir.mkdir(path); - } - - return path; -} - -// 保存接收文件路径 -void Settings::savePath(QString path) -{ - // Save the new path - mSettings.setValue("DestPath", path); - mSettings.sync(); -} - -// 保存窗口位置 -//void Settings::saveWindowGeometry(QByteArray geo) -//{ -// mSettings.setValue("WindowPosAndSize", geo); -// mSettings.sync(); -//} - -void Settings::saveWindowGeometry(QRect geo) -{ - mSettings.setValue("WindowPosAndSize", geo); - mSettings.sync(); -} - -// 获取窗口位置 -QRect Settings::windowGeometry() -{ - return (mSettings.value("WindowPosAndSize")).toRect(); -} - -// 保存主题颜色 -void Settings::saveThemeColor(QString color) -{ - mSettings.setValue("ThemeColor", color); - mSettings.sync(); -} - -// 获取主题颜色 -QString Settings::themeColor() -{ - return mSettings.value("ThemeColor", Theme::DEFAULT_THEME_COLOR).toString(); -} - -/* -* Summary: get friend name -* Return : friend name -*/ -QString Settings::buddyName() -{ - // Retrieve the last saved name (if any) - return mSettings.value("BuddyName", "User").toString(); - -} - -/* -* Summary: save friend name -* Parameters: -* name: new friend name -* Return : -*/ -void Settings::saveBuddyName(QString name) -{ - // Save the new name - mSettings.setValue("BuddyName", name); - mSettings.sync(); -} - -// 保存昵称和备注 -/* -* Summary: save nickname -* Parameters: -* ip: my mac or friend's mac -* nickname: my nickname or friend's nickname -* Return : -*/ -void Settings::saveNickname(QString mac, QString nickname) -{ - mSettings.setValue(mac, nickname); - mSettings.sync(); -} - -// 获取昵称和备注 -/* -* Summary: save nickname -* Parameters: -* ip: my mac or friend's mac -* Return : -* nickname: my nickname or friend's nickname -*/ -QString Settings::nickname(QString mac) -{ - // 昵称默认"error" - return mSettings.value(mac, "error").toString(); -} - -// 保存图标路径 -void Settings::saveIconPath(QString path) -{ - mSettings.setValue("IconPath", path); -} - -// 获取图标路径 -QString Settings::iconPath() -{ - // 路径默认"" - return mSettings.value("IconPath", "").toString(); -} diff --git a/settings.h b/settings.h deleted file mode 100644 index 6167cde..0000000 --- a/settings.h +++ /dev/null @@ -1,71 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef SETTINGS_H -#define SETTINGS_H - -#include -#include -#include -#include -#include - -// 错误类型 -enum errorCode { - CONN_SUCCESS, - CONN_TIMEOUT, - DISCONN, - TRANSFERERR, - TRY_RECONN, - SKIPFILE, - OTHER -}; - -class Settings : public QObject -{ - Q_OBJECT -public: - explicit Settings(QObject *parent = 0); - QString currentPath(); - void savePath(QString path); -// void saveWindowGeometry(QByteArray geo); -// QByteArray windowGeometry(); - void saveWindowGeometry(QRect geo); - QRect windowGeometry(); - void saveThemeColor(QString color); - QString themeColor(); - void saveShowTermsOnStart(bool show); - bool showTermsOnStart(); - QString buddyName(); - void saveBuddyName(QString name); - void saveNickname(QString mac, QString nickname); - QString nickname(QString mac); - void saveIconPath(QString path); - QString iconPath(); - -signals: - -public slots: - -private: - QSettings mSettings; - -}; - -#endif // SETTINGS_H diff --git a/src/controller/control.cpp b/src/controller/control.cpp new file mode 100644 index 0000000..846be07 --- /dev/null +++ b/src/controller/control.cpp @@ -0,0 +1,80 @@ +#include "control.h" + +Control::Control() +{ + init(); + establishInterrupt(); + + /* 模拟客户端 */ + g_udpItem item; + item.uuid = QString("0x7777777"); + item.peerListenIp = QString("172.20.3.250"); + item.peerListenPort = QString("6066"); + GlobalData::getInstance()->m_tcpLink.udpMaintainAdd(item); + + g_send send; + send.uuid = QString("0x7777777"); + send.type = QString("msg"); + send.msgData = QString("阿萨德;放假啊商店里;放假啊搜到放假哦啊配送积分大设计费"); + + slotSend(send); + +} + +Control::~Control() +{ + if (this->m_client != NULL) { + delete this->m_client; + } + + if (this->m_server != NULL) { + delete this->m_server; + } + + if (this->m_udpSocket != NULL) { + delete this->m_udpSocket; + } + +} + +void Control::init(void) +{ + /* 实例全局数据模块 */ + GlobalData::getInstance(); + + this->m_server = new TcpServer; + this->m_client = new TcpClient; + this->m_udpSocket = new UdpSocket; + + return; +} + +void Control::establishInterrupt(void) +{ + connect(this->m_server , &TcpServer::sigTcpServerRecvMsgSuccess , this , &Control::slotRecvMsgSuccess); + connect(this->m_server , &TcpServer::sigTcpServerSendMsgSuccess , this , &Control::slotSendMsgSuccess); + connect(this->m_client , &TcpClient::sigTcpClientRecvMsgSuccess , this , &Control::slotRecvMsgSuccess); + connect(this->m_client , &TcpClient::sigTcpClientSendMsgSuccess , this , &Control::slotSendMsgSuccess); + + + return; +} + +void Control::slotSend(g_send send) +{ + this->m_client->tran(send); +} + +void Control::slotRecvMsgSuccess(g_recv recv) +{ + qDebug() << "Debug : Control , slotRecvMsgSuccess , recv msg ---> " << recv.msgData; + + return; +} + +void Control::slotSendMsgSuccess(g_send send) +{ + qDebug() << "Debug , Control , slotSendMsgSuccess , send msg ---> " << send.msgData; + + return; +} diff --git a/src/controller/control.h b/src/controller/control.h new file mode 100644 index 0000000..a19f024 --- /dev/null +++ b/src/controller/control.h @@ -0,0 +1,34 @@ +#ifndef __CONTROL_H__ +#define __CONTROL_H__ + +#include + +#include "global/utils/global_data.h" +#include "network/tcp_server.h" +#include "network/tcp_client.h" +#include "network/udp_socket.h" + +class Control : public QObject +{ + Q_OBJECT + +public: + Control(); + ~Control(); + + void init(void); + void establishInterrupt(void); + +private: + TcpServer *m_server; + TcpClient *m_client; + UdpSocket *m_udpSocket; + +private slots: + void slotSend(g_send send); + void slotRecvMsgSuccess(g_recv recv); + void slotSendMsgSuccess(g_send send); +}; + + +#endif diff --git a/src/controller/interface.h b/src/controller/interface.h new file mode 100644 index 0000000..cf63be6 --- /dev/null +++ b/src/controller/interface.h @@ -0,0 +1,5 @@ +#ifndef INTERACTION_H +#define INTERACTION_H + + +#endif // INTERACTION_H diff --git a/src/global/database/database.cpp b/src/global/database/database.cpp new file mode 100644 index 0000000..12ea928 --- /dev/null +++ b/src/global/database/database.cpp @@ -0,0 +1,343 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "database.h" + +FriendInfoData::FriendInfoData(int m_friendId, + QString m_friendUuid, + QString m_friendIp, + int m_friendPort, + QString m_friendMac, + QString m_username, + QString m_nickname, + QString m_system, + QString m_platform, + QString m_avatarUrl, + QString m_recentMsgCont, + QString m_recentMsgTime, + int m_unreadMsgNum, + int m_priority) +{ + this->m_friendId = m_friendId; + this->m_friendUuid = m_friendUuid; + this->m_friendIp = m_friendIp; + this->m_friendPort = m_friendPort; + this->m_friendMac = m_friendMac; + this->m_username = m_username; + this->m_nickname = m_nickname; + this->m_system = m_system; + this->m_platform = m_platform; + this->m_avatarUrl = m_avatarUrl; + this->m_recentMsgCont = m_recentMsgCont; + this->m_recentMsgTime = m_recentMsgTime; + this->m_unreadMsgNum = m_unreadMsgNum; + this->m_priority = m_priority; +} + +FriendInfoData::FriendInfoData(QMap strMap, QMap intMap) +{ + // if (strMap.isEmpty() || intMap.isEmpty()) { + // return ; + // } + + // QString类型变量赋值 + if (strMap.contains("m_friendUuid")) { + m_friendUuid = strMap["m_friendUuid"]; + } + if (strMap.contains("m_friendIp")) { + m_friendIp = strMap["m_friendIp"]; + } + if (strMap.contains("m_friendMac")) { + m_friendMac = strMap["m_friendMac"]; + } + if (strMap.contains("m_username")) { + m_username = strMap["m_username"]; + } + if (strMap.contains("m_nickname")) { + m_nickname = strMap["m_nickname"]; + } + if (strMap.contains("m_system")) { + m_system = strMap["m_system"]; + } + if (strMap.contains("m_platform")) { + m_platform = strMap["m_platform"]; + } + if (strMap.contains("m_avatarUrl")) { + m_avatarUrl = strMap["m_avatarUrl"]; + } + if (strMap.contains("m_recentMsgCont")) { + m_recentMsgCont = strMap["m_recentMsgCont"]; + } + if (strMap.contains("m_recentMsgTime")) { + m_recentMsgTime = strMap["m_recentMsgTime"]; + } + + // int类型变量赋值 + if (intMap.contains("m_friendId")) { + m_friendId = intMap["m_friendId"]; + } + if (intMap.contains("m_friendPort")) { + m_friendPort = intMap["m_friendPort"]; + } + if (intMap.contains("m_unreadMsgNum")) { + m_unreadMsgNum = intMap["m_unreadMsgNum"]; + } + if (intMap.contains("m_priority")) { + m_priority = intMap["m_priority"]; + } +} + +FriendInfoData::~FriendInfoData() +{ +} + + +FriendInfoDataBase::FriendInfoDataBase(QObject *parent) : QObject(parent) +{ + m_dbName = "kylin-messages.db"; + m_dbTableName = "friend_info"; + + // 打开数据库 + m_db = QSqlDatabase::addDatabase("QSQLITE"); + m_db.setDatabaseName(QApplication::applicationDirPath() + "/../../data/database/" + m_dbName); + + qDebug() << QApplication::applicationDirPath() + "/../../data/database/" + m_dbName; + + if (!m_db.open()) { + m_dbName = ""; + m_dbTableName = ""; + QMessageBox::warning(0, QObject::tr("Database Error"), + m_db.lastError().text()); + } + + // 使用model + m_model = new QSqlTableModel(this, m_db); + m_model->setTable(m_dbTableName); + // 提交后才修改数据库 + m_model->setEditStrategy(QSqlTableModel::OnManualSubmit); + + m_model->select(); +} + +FriendInfoDataBase::~FriendInfoDataBase() +{ + +} + +FriendInfoDataBase* FriendInfoDataBase::getInstance() +{ + static FriendInfoDataBase *instance = nullptr; + + if (instance == nullptr) { + try { + instance = new FriendInfoDataBase(); + } + catch (const std::runtime_error &re) + { + qDebug() << "runtime_error:" << re.what(); + } + } + + return instance; +} + +// 插入数据 +// TODO 数据加密处理 +bool FriendInfoDataBase::insertData(FriendInfoData *friendInfo) +{ + int col = m_model->columnCount(); + int row = m_model->rowCount(); + int index = 0; + + m_model->insertRow(row); + index++; + // m_model->setData(m_model->index(row, index++), friendInfo->m_friendId); + m_model->setData(m_model->index(row, index++), friendInfo->m_friendUuid); + m_model->setData(m_model->index(row, index++), friendInfo->m_friendIp); + m_model->setData(m_model->index(row, index++), friendInfo->m_friendPort); + m_model->setData(m_model->index(row, index++), friendInfo->m_friendMac); + m_model->setData(m_model->index(row, index++), friendInfo->m_username); + m_model->setData(m_model->index(row, index++), friendInfo->m_nickname); + m_model->setData(m_model->index(row, index++), friendInfo->m_system); + m_model->setData(m_model->index(row, index++), friendInfo->m_platform); + m_model->setData(m_model->index(row, index++), friendInfo->m_avatarUrl); + m_model->setData(m_model->index(row, index++), friendInfo->m_recentMsgCont); + m_model->setData(m_model->index(row, index++), friendInfo->m_recentMsgTime); + m_model->setData(m_model->index(row, index++), friendInfo->m_unreadMsgNum); + m_model->setData(m_model->index(row, index++), friendInfo->m_priority); + + // 提交修改 + m_model->submitAll(); + m_model->select(); + + return true; +} + +// 查询数据 +bool FriendInfoDataBase::queryData(FriendInfoData *friendInfo) +{ + return m_model->select(); +} + +// 更新数据 +// TODO 获取行号 +bool FriendInfoDataBase::updateData(FriendInfoData *friendInfo) +{ + // 示例 + // 使用model必须要获取到行号和列号 + int row = 0; + int col = 0; + + m_model->setData(m_model->index(row, col), friendInfo->m_priority); + + m_model->submitAll(); + + // TODO 使用query获取行号 + QString queryIndex = QString("SELECT rowid from %1 where friend_id = %2") + .arg(m_dbTableName).arg(friendInfo->m_friendId); + query.prepare(queryIndex); + return query.exec(); +} + +// 删除数据 +bool FriendInfoDataBase::deleteData(FriendInfoData *friendInfo) +{ + // 示例 + int delRow = 0; + + m_model->removeRow(delRow); + m_model->submitAll(); + return m_model->select(); +} + +/************************************************************************** +* 函数名称:updatePriority +* 函数功能:修改好友的优先级 +* 输入参数:FriendInfoData +* 返回数值:bool +* 创建人员: +* 创建时间:2021-05-06 +* 修改人员: +* 修改时间: +**************************************************************************/ +bool FriendInfoDataBase::updatePriority(FriendInfoData *friendInfo) +{ + // 使用query + QString updateSql = QString("update %1 set priority = %2 where friend_id = %3") + .arg(m_dbTableName).arg(friendInfo->m_priority).arg(friendInfo->m_friendId); + query.prepare(updateSql); + return query.exec(); +} + +/************************************************************************** +* 函数名称:updateNickname +* 函数功能:修改好友的备注名 +* 输入参数:FriendInfoData +* 返回数值:bool +* 创建人员: +* 创建时间:2021-05-06 +* 修改人员: +* 修改时间: +**************************************************************************/ +bool FriendInfoDataBase::updateNickname(FriendInfoData *friendInfo) +{ + // 使用query + QString updateSql = QString("update %1 set nickname = %2 where friend_id = %3") + .arg(m_dbTableName).arg(friendInfo->m_nickname).arg(friendInfo->m_friendId); + query.prepare(updateSql); + return query.exec(); +} + +/************************************************************************** +* 函数名称: queryInfoById +* 函数功能: 根据ID获取好友信息 +* 输入参数: friendId +* 返回数值: FriendInfoData +* 创建人员: +* 创建时间: 2021-05-06 +* 修改人员: +* 修改时间: +**************************************************************************/ +FriendInfoData *FriendInfoDataBase::queryInfoById(int friendId) +{ + // 使用query + QString querySql = QString("select * from %1 where friend_id = %2") + .arg(m_dbTableName).arg(friendId); + query.prepare(querySql); + query.exec(); + + FriendInfoData *friendInfo = new FriendInfoData(); + + if (query.next()) { + friendInfo->m_friendId = query.value("friend_id").toInt(); + friendInfo->m_friendUuid = query.value("friend_uuid").toString(); + friendInfo->m_friendIp = query.value("friend_ip").toString(); + friendInfo->m_friendPort = query.value("friend_port").toInt(); + friendInfo->m_friendMac = query.value("friend_mac").toString(); + friendInfo->m_username = query.value("user_name").toString(); + friendInfo->m_nickname = query.value("nickname").toString(); + friendInfo->m_system = query.value("system").toString(); + friendInfo->m_platform = query.value("platform").toString(); + friendInfo->m_avatarUrl = query.value("avatar_url").toString(); + friendInfo->m_recentMsgCont = query.value("recent_msg_content").toString(); + friendInfo->m_recentMsgTime = query.value("recent_msg_time").toString(); + friendInfo->m_unreadMsgNum = query.value("unread_msg_num").toInt(); + friendInfo->m_priority = query.value("priority").toInt(); + } + + return friendInfo; +} + +/************************************************************************** +* 函数名称: queryInfoByUuid +* 函数功能: 根据UUID获取好友信息 +* 输入参数: friendUuid +* 返回数值: FriendInfoData +* 创建人员: +* 创建时间: 2021-05-06 +* 修改人员: +* 修改时间: +**************************************************************************/ +FriendInfoData *FriendInfoDataBase::queryInfoByUuid(QString friendUuid) +{ + // 使用query + QString querySql = QString("select * from %1 where friend_uuid = %2") + .arg(m_dbTableName).arg(friendUuid); + query.prepare(querySql); + query.exec(); + + FriendInfoData *friendInfo = new FriendInfoData(); + + if (query.next()) { + friendInfo->m_friendId = query.value("friend_id").toInt(); + friendInfo->m_friendUuid = query.value("friend_uuid").toString(); + friendInfo->m_friendIp = query.value("friend_ip").toString(); + friendInfo->m_friendPort = query.value("friend_port").toInt(); + friendInfo->m_friendMac = query.value("friend_mac").toString(); + friendInfo->m_username = query.value("user_name").toString(); + friendInfo->m_nickname = query.value("nickname").toString(); + friendInfo->m_system = query.value("system").toString(); + friendInfo->m_platform = query.value("platform").toString(); + friendInfo->m_avatarUrl = query.value("avatar_url").toString(); + friendInfo->m_recentMsgCont = query.value("recent_msg_content").toString(); + friendInfo->m_recentMsgTime = query.value("recent_msg_time").toString(); + friendInfo->m_unreadMsgNum = query.value("unread_msg_num").toInt(); + friendInfo->m_priority = query.value("priority").toInt(); + } + + return friendInfo; +} \ No newline at end of file diff --git a/src/global/database/database.h b/src/global/database/database.h new file mode 100644 index 0000000..8ac9de8 --- /dev/null +++ b/src/global/database/database.h @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DATABASE_H +#define DATABASE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class FriendInfoData +{ +public: + FriendInfoData(int m_friendId = 0, + QString m_friendUuid = "", + QString m_friendIp = "", + int m_friendPort = 0, + QString m_friendMac = "", + QString m_username = "", + QString m_nickname = "", + QString m_system = "", + QString m_platform = "", + QString m_avatarUrl = "", + QString m_recentMsgCont = "", + QString m_recentMsgTime = "", + int m_unreadMsgNum = 0, + int m_priority = 0); + + FriendInfoData(QMap strMap, QMap intMap); + ~FriendInfoData(); + + int m_friendId = 0; + QString m_friendUuid = ""; + QString m_friendIp = ""; + int m_friendPort = 0; + QString m_friendMac = ""; + QString m_username = ""; + QString m_nickname = ""; + QString m_system = ""; + QString m_platform = ""; + QString m_avatarUrl = ""; + QString m_recentMsgCont = ""; + QString m_recentMsgTime = ""; + int m_unreadMsgNum = 0; + int m_priority = 0; + + enum strRole { + e_friendUuid = 0, + e_friendIp, + e_friendMac, + e_username, + e_nickname, + e_system, + e_platform, + e_avatarUrl, + e_recentMsgCont, + e_recentMsgTime, + }; + + enum intRole { + e_friendId = 0, + e_friendPort, + e_unreadMsgNum, + e_priority, + }; +}; + +class FriendInfoDataBase : public QObject +{ + Q_OBJECT +public: + explicit FriendInfoDataBase(QObject *parent = nullptr); + ~FriendInfoDataBase(); + + //单例,初始化返回指针,完成数据库文件建立 + static FriendInfoDataBase* getInstance(); + + // 插入数据 + bool insertData(FriendInfoData *friendInfo); + + // 查询数据 + bool queryData(FriendInfoData *friendInfo); + + // 更新数据 + bool updateData(FriendInfoData *friendInfo); + + // 删除数据 + bool deleteData(FriendInfoData *friendInfo); + + // 更新好友优先级 + bool updatePriority(FriendInfoData *friendInfo); + + // 更新好友备注 + bool updateNickname(FriendInfoData *friendInfo); + + // 根据ID获取好友信息 + FriendInfoData *queryInfoById(int friendId); + + // 根据UUID获取好友信息 + FriendInfoData *queryInfoByUuid(QString friendUuid); + + QSqlTableModel* m_model; + + QSqlQuery query; + +private: + QSqlDatabase m_db; + QString m_dbName; + QString m_dbTableName; + + + enum { + UPDATE = 0, + INSERT, + DELETE + }; + int m_operator; +}; + + + + +#endif // DATABASE_H \ No newline at end of file diff --git a/src/global/declare/declare.h b/src/global/declare/declare.h new file mode 100644 index 0000000..c241885 --- /dev/null +++ b/src/global/declare/declare.h @@ -0,0 +1,60 @@ +#ifndef __DECLARE_H__ +#define __DECLARE_H__ + +#include + +class TcpModule; + +/* 代表tcp链接表的一条数据 */ +typedef struct TcpMaintain +{ + QString uuid; + QString selfIp; + QString selfPort; + QString peerIp; + QString peerPort; + QString peerListenIp; + QString peerListenPort; + TcpModule *module; +} g_tcpMaintain; + +/* tcp维护tcp链接表 */ +typedef struct TcpItem +{ + QString uuid; + QString selfIp; + QString selfPort; + QString peerIp; + QString peerPort; + TcpModule *module; +} g_tcpItem; + +/* udp维护tcp链接表 */ +typedef struct UdpItem +{ + QString uuid; + QString peerListenIp; + QString peerListenPort; +} g_udpItem; + +/* 发送数据结构 */ +typedef struct Send +{ + QString uuid; + QString type; + QString msgData; + QString fileName; + QString filePath; +} g_send; + +/* 接受数据结构 */ +typedef struct Recv +{ + QString uuid; + QString type; + QString msgData; + QString fileName; + QString filePath; +} g_recv; + +#endif diff --git a/src/global/utils/global_data.cpp b/src/global/utils/global_data.cpp new file mode 100644 index 0000000..72a0075 --- /dev/null +++ b/src/global/utils/global_data.cpp @@ -0,0 +1,72 @@ +#include "global_data.h" + +#include +#include +#include +#include + +#define TCP_LISTEN_PORT "6066" +#define UDP_LISTEN_PORT "6067" + +GlobalData::GlobalData() +{ + init(); +} + +GlobalData::~GlobalData() +{ + +} + +GlobalData *GlobalData::getInstance(void) +{ + static GlobalData *s_globalData; + if (s_globalData == NULL) { + s_globalData = new GlobalData; + } + + return s_globalData; +} + +void GlobalData::init(void) +{ + getTcpListenIp(); + getTcpListenPort(); + getUdpListenPort(); + getUuid(); + + return; +} + +/* 取第一个ipv4地址 , 进行监听 */ +void GlobalData::getTcpListenIp(void) +{ + QList ipList = QNetworkInterface::allAddresses(); + + for (int i = 0 ; i < ipList.count() ; i++) { + if (ipList.at(i) != QHostAddress::LocalHost && ipList.at(i).toIPv4Address()) { + this->m_tcpListenIP = ipList.at(i).toString(); + break; + } + } + return; +} + +void GlobalData::getTcpListenPort(void) +{ + this->m_tcpListenPort = QString(TCP_LISTEN_PORT); + return; +} + +void GlobalData::getUdpListenPort(void) +{ + this->m_udpListenPort = QString(UDP_LISTEN_PORT); + return; +} + +void GlobalData::getUuid(void) +{ + this->m_uuid = QString("0x7777777"); + + return; +} diff --git a/src/global/utils/global_data.h b/src/global/utils/global_data.h new file mode 100644 index 0000000..92a9f6e --- /dev/null +++ b/src/global/utils/global_data.h @@ -0,0 +1,36 @@ +#ifndef __GLOBAL_DATA_H__ +#define __GLOBAL_DATA_H__ + +#include "tcp_link.h" + +#include + +class GlobalData +{ +public: + ~GlobalData(); + + /* 本机信息 */ + QString m_uuid; + QString m_tcpListenIP; + QString m_tcpListenPort; + QString m_udpListenPort; + + /* tcp链接表 */ + TcpLink m_tcpLink; + +private: + GlobalData(); +public: + static GlobalData *getInstance(); + +private: + void init(void); + void getTcpListenIp(void); + void getTcpListenPort(void); + void getUdpListenPort(void); + void getUuid(void); +}; + +#endif + diff --git a/src/global/utils/tcp_link.cpp b/src/global/utils/tcp_link.cpp new file mode 100644 index 0000000..ad7fe8e --- /dev/null +++ b/src/global/utils/tcp_link.cpp @@ -0,0 +1,278 @@ +#include "tcp_link.h" + +#include + +TcpLink::TcpLink() +{ + if (init()) { + qDebug() << "Error : TcpLink , init fail\n"; + } +} + +TcpLink::~TcpLink() +{ + for (int i = 0 ; i < this->m_tcpMaintain.count() ; i++) { + g_tcpMaintain *tmp = this->m_tcpMaintain.at(i); + + if (tmp->module != NULL) { + delete tmp->module; + } + + delete tmp; + } +} + +int TcpLink::init() +{ + /* 初始化读写锁 */ + if (pthread_rwlock_init(&(this->m_rwLock) , NULL)) { + qDebug() << "Error : TcpLink , init , init rwLock fail"; + return -1; + } + + return 0; +} + +int TcpLink::tcpMaintainAdd(g_tcpItem item) +{ + int flag = -1; + + if (pthread_rwlock_wrlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , tcpMaintainAdd , lock rwLock fail"; + return -1; + } + + for (int i = 0 ; i < this->m_tcpMaintain.count() ; i++) { + g_tcpMaintain *tmp = this->m_tcpMaintain.at(i); + + if (tmp->uuid == item.uuid) { + tmp->selfIp = item.selfIp; + tmp->selfPort = item.selfPort; + tmp->peerIp = item.peerIp; + tmp->peerPort = item.peerPort; + tmp->module = item.module; + + flag = 0; + break; + } + } + + if (pthread_rwlock_unlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , tcpMaintainAdd , unlock rwLock fail"; + return -1; + } + + if (flag) { + qDebug() << "Waring : TcpLink , tcpMaintainAdd , uuid dont find!!!"; + } + + return 0; +} + + +/* 此函数并没有释放tcp module实例 , 释放的话函数返回会造成崩溃 , 不释放会造成内存泄露 , 有待优化 */ +int TcpLink::tcpMaintainDelete(QString uuid) +{ + int flag = -1; + + if (pthread_rwlock_wrlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , tcpMaintainDelete , lock rwLock fail"; + return -1; + } + + for (int i = 0 ; i < this->m_tcpMaintain.count() ; i++) { + g_tcpMaintain *tmp = this->m_tcpMaintain.at(i); + + if (tmp->uuid == uuid) { + tmp->selfIp.clear(); + tmp->selfPort.clear(); + tmp->peerIp.clear(); + tmp->peerPort.clear(); + tmp->module = NULL; + + flag = 0; + + break; + } + } + + if (pthread_rwlock_unlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , tcpMaintainDelete , unlock rwLock fail"; + return -1; + } + + if (flag) { + qDebug() << "Waring : TcpLink , tcpMaintainDelete , uuid dont find!!!"; + } + + return 0; +} + +int TcpLink::udpMaintainAdd(g_udpItem item) +{ + /* 变量没被改变 -> 不存在 , 新添 */ + /* 变量被置0 -> 存在 , 覆盖 */ + int flag = -1; + + g_tcpMaintain *newItem; + + if (pthread_rwlock_wrlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , udpMaintainAdd , lock rwLock fail"; + return -1; + } + + for (int i = 0 ; i < this->m_tcpMaintain.count() ; i++) { + g_tcpMaintain *tmp = this->m_tcpMaintain.at(i); + + if (tmp->uuid == item.uuid) { + tmp->uuid = item.uuid; + tmp->peerListenIp = item.peerListenIp; + tmp->peerListenPort = item.peerListenPort; + + flag = 0; + goto FLAG; + } + } + + /* 不存在相同uuid , 新增一条 */ + newItem = new g_tcpMaintain; + newItem->module = NULL; + + newItem->uuid = item.uuid; + newItem->peerListenIp = item.peerListenIp; + newItem->peerListenPort = item.peerListenPort; + + this->m_tcpMaintain.push_back(newItem); + +FLAG: + if (pthread_rwlock_unlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , udpMaintainAdd , unlock rwLock fail"; + return -1; + } + + if (flag == -1) { + return 1; + } else { + return 0; + } +} + +int TcpLink::udpMaintainDelete(QString uuid) +{ + int flag = -1; + + if (pthread_rwlock_wrlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , udpMaintainDelete , lock rwLock fail"; + return -1; + } + + for (int i = 0 ; i < this->m_tcpMaintain.count() ; i++) { + g_tcpMaintain *tmp = this->m_tcpMaintain.at(i); + if (tmp->uuid == uuid) { + if (tmp->module != NULL) { + /* 释放tcp module */ + delete tmp->module; + } + + /* 释放该条记录 */ + delete tmp; + + /* 从list中移除记录 */ + this->m_tcpMaintain.removeAt(i); + flag = 0; + + break; + } + } + + if (pthread_rwlock_unlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , udpMaintainDelete , unlock rwLock fail"; + return -1; + } + + if (flag) { + qDebug() << "Waring : TcpLink , udpMaintainDelete , uuid dont find!!!"; + } + + return 0; +} + +void TcpLink::ergodic() +{ + if (pthread_rwlock_rdlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , ergodic , lock rwLock fail"; + return; + } + + qDebug() << "Info : tcpMaintain ergodic ......"; + qDebug() << "uuid selfIp selfPort peerIp peerPort peerListenIp peerListenPort module"; + + for (int i = 0 ; i < this->m_tcpMaintain.count() ; i++) { + g_tcpMaintain *tmp = this->m_tcpMaintain.at(i); + + std::string stdUuid = tmp->uuid.toStdString(); + const char *uuid = stdUuid.c_str(); + + std::string stdSelfIp = tmp->selfIp.toStdString(); + const char *selfIp = stdSelfIp.c_str(); + + std::string stdSelfPort = tmp->selfPort.toStdString(); + const char *selfPort = stdSelfPort.c_str(); + + std::string stdPeerIP = tmp->peerIp.toStdString(); + const char *peerIp = stdPeerIP.c_str(); + + std::string stdPeerPort = tmp->peerPort.toStdString(); + const char *peerPort = stdPeerPort.c_str(); + + std::string stdPeerListenIp = tmp->peerListenIp.toStdString(); + const char *peerListenIp = stdPeerListenIp.c_str(); + + std::string stdPeerListenPort = tmp->peerListenPort.toStdString(); + const char *peerListenPort = stdPeerListenPort.c_str(); + + printf("[%s] [%s] [%s] [%s] [%s] [%s] [%s] [%x]\n" , uuid , selfIp , selfPort , peerIp , peerPort , peerListenIp , peerListenPort , tmp->module); + } + + if (pthread_rwlock_unlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , ergodic , unlock rwLock fail"; + return ; + } + + return ; +} + +g_tcpMaintain TcpLink::select(QString uuid) +{ + g_tcpMaintain item; + item.module = NULL; + + if (pthread_rwlock_rdlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , select , lock rwLock fail"; + return item; + } + + for (int i = 0 ; i < this->m_tcpMaintain.count() ; i++) { + g_tcpMaintain *tmp = this->m_tcpMaintain.at(i); + + if (tmp->uuid == uuid) { + item.uuid = tmp->uuid; + item.selfIp = tmp->selfIp; + item.selfPort = tmp->selfPort; + item.peerIp = tmp->peerIp; + item.peerPort = tmp->peerPort; + item.peerListenIp = tmp->peerListenIp; + item.peerListenPort = tmp->peerListenPort; + item.module = tmp->module; + + break; + } + } + + if (pthread_rwlock_unlock(&(this->m_rwLock))) { + qDebug() << "Error : TcpLink , select , unlock rwLock fail"; + return item; + } + + return item; +} diff --git a/src/global/utils/tcp_link.h b/src/global/utils/tcp_link.h new file mode 100644 index 0000000..f1b8e80 --- /dev/null +++ b/src/global/utils/tcp_link.h @@ -0,0 +1,28 @@ +#ifndef __TCP_LINK_H__ +#define __TCP_LINK_H__ + +#include +#include + +#include "global/declare/declare.h" + +class TcpLink +{ +public: + TcpLink(); + ~TcpLink(); + + int init(); + void ergodic(void); + int tcpMaintainAdd(g_tcpItem); + int tcpMaintainDelete(QString uuid); + int udpMaintainAdd(g_udpItem); + int udpMaintainDelete(QString uuid); + g_tcpMaintain select(QString uuid); + +private: + pthread_rwlock_t m_rwLock; + QList m_tcpMaintain; +}; + +#endif diff --git a/src/global/utils/utils.h b/src/global/utils/utils.h new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..be6593e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2011 Emanuele Colombo + * 2020 KylinSoft Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include + +#include +#include +#include +#include + +#include "controller/control.h" +#include "network/tcp_client.h" +#include "network/udp_socket.h" +#include "global/utils/global_data.h" +#include "global/declare/declare.h" + +#include "view/kyview.h" +#include "view/common/xatom-helper.h" +#include "view/common/dbusadaptor.h" + +int main(int argc, char *argv[]) +{ +//#if 0 + /* 用于测试网络模块 模拟客户端*/ +// { +// QApplication app(argc , argv); + +// Control *control = new Control; +// #if 0 +// g_udpItem item; +// item.uuid = QString("0x7777777"); +// item.peerListenIp = QString("172.20.3.250"); +// item.peerListenPort = QString("6066"); +// GlobalData::getInstance()->m_tcpLink.udpMaintainAdd(item); + +// g_send send; +// send.uuid = QString("0x7777777"); +// send.type = QString("msg"); +// send.msgData = QString("阿萨德;放假啊商店里;放假啊搜到放假哦啊配送积分大设计费"); + +// TcpClient *client = new TcpClient; +// client->tran(send); +// #endif + +// app.exec(); +// } + +//#endif + // 统一日志输出 + // initUkuiLog4qt("kylin-ipmsg"); + + // 适配4K屏以及分数缩放 + #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + #endif + + #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + #endif + + QApplication app(argc, argv); + app.setApplicationVersion("2.1.1"); + + // 设置不使用gtk3平台文件对话框 + app.setProperty("useFileDialog", false); + + // 连接DBus服务 + QDBusInterface interface(KYLIN_MESSAGES_SERVICE, + KYLIN_MESSAGES_PATH, + KYLIN_MESSAGES_INTERFACE, + QDBusConnection::sessionBus()); + if (interface.isValid()) { + // 调用拉起主界面的method + interface.call("showMainWindow"); + interface.call("showMainWindow"); + } + + // 文件锁实现VNC单例 + QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); + // 需要给文件锁加一个DISPLAY标识 + int fd = open(QString(homePath.at(0) + "/.config/kylin-messages%1.lock").arg(getenv("DISPLAY")).toUtf8().data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) + { + exit(1); + } + if (lockf(fd, F_TLOCK, 0)) + { + syslog(LOG_ERR, "Can't lock single file, kylin-messages is already running!"); + exit(0); + } + + // 国际化 + QString qtTransPath; + // /usr/share/qt5/translations + qtTransPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); + QString kylinMessagesTransPath; + +#ifdef QT_NO_DEBUG + if (QDir("/usr/share/kylin-messages/translations").exists()) { + kylinMessagesTransPath = "/usr/share/kylin-messages/translations"; + } + else { + kylinMessagesTransPath = qApp->applicationDirPath() + "/.qm"; + } +#else + kylinMessagesTransPath = "translations"; +#endif + + QString locale = QLocale::system().name(); + QTranslator trans_global, trans_qt; + if (locale == "zh_CN") { + if(!trans_global.load(QLocale(), "kylin-messages", "_", kylinMessagesTransPath)) + qDebug() << "Load translations file" <setWindowMotifHint(KyView::getInstance()->winId(), hints); +#endif + + KyView::getInstance()->show(); + + // 创建DBus服务 + DbusAdaptor adaptor; + Q_UNUSED(adaptor); + + return app.exec(); +} diff --git a/src/model/chatlogmodel.cpp b/src/model/chatlogmodel.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/model/chatlogmodel.h b/src/model/chatlogmodel.h new file mode 100644 index 0000000..e69de29 diff --git a/src/model/friendlistmodel.cpp b/src/model/friendlistmodel.cpp new file mode 100644 index 0000000..aaa3b96 --- /dev/null +++ b/src/model/friendlistmodel.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "friendlistmodel.h" + +FriendListModel::FriendListModel() : + QStandardItemModel(NULL) +{ + QHash roleNames; + roleNames[Id] = "id"; + roleNames[Uuid] = "uuid"; + roleNames[Ip] = "ip"; + roleNames[Port] = "port"; + roleNames[Mac] = "mac"; + roleNames[Username] = "username"; + roleNames[Username] = "nickname"; + roleNames[System] = "system"; + roleNames[Platform] = "platform"; + roleNames[Avatar] = "avatar"; + roleNames[RecentMsgContent] = "recentMsgContent"; + roleNames[RecentMsgTime] = "recentMsgTime"; + roleNames[UnreadMsgNum] = "unreadMsgNum"; + roleNames[OnlineState] = "onlineState"; + roleNames[Priority] = "priority"; + setItemRoleNames(roleNames); +} + +FriendListModel::~FriendListModel() +{ +} + +void FriendListModel::addFriend() +{ + QStandardItem *newItem = NULL; + + // Check if the same uuid is alreay in the friend list + + QString avatar = "Z"; + QString nickname = "Zhangsan"; + QString msgContent = "listview"; + QString msgTime = "10:22"; + QString msgNum = "5"; + + newItem = new QStandardItem(); + newItem->setData(avatar, FriendListModel::Avatar); + newItem->setData(nickname, FriendListModel::Nickname); + newItem->setData(msgContent, FriendListModel::RecentMsgContent); + newItem->setData(msgTime, FriendListModel::RecentMsgTime); + newItem->setData(msgNum, FriendListModel::UnreadMsgNum); + newItem->setData(true, FriendListModel::OnlineState); + + appendRow(newItem); + + FriendInfoDataBase::getInstance(); + + QMap strMap; + QMap intMap; + strMap.insert("m_friendUuid", QUuid::createUuid().toString()); + strMap.insert("m_avatarUrl", avatar); + strMap.insert("m_nickname", nickname); + FriendInfoDataBase::getInstance()->insertData(new FriendInfoData(strMap, intMap)); +} +void FriendListModel::updateFriend() +{ + this->item(0)->setData("Zhaoyun", FriendListModel::Nickname); +} + +void removeFriend(QString uuid) +{ + +} \ No newline at end of file diff --git a/src/model/friendlistmodel.h b/src/model/friendlistmodel.h new file mode 100644 index 0000000..f389803 --- /dev/null +++ b/src/model/friendlistmodel.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef FRIENDLISTMODEL_H +#define FRIENDLISTMODEL_H + +#include +#include +#include +#include + +#include "../global/database/database.h" + +class FriendListModel : public QStandardItemModel +{ + Q_OBJECT +public: + explicit FriendListModel(); + ~FriendListModel(); + + // 添加好友 + void addFriend(); + + // 更新好友信息 + void updateFriend(); + + // 更新好友状态 + // void updateFriendState(QString uuid, bool isOnline); + + // 删除好友 + void removeFriend(QString uuid); + + QStandardItem *friendById(QString id); + QStandardItem *friendByUuid(QString uuid); + + enum FriendRoles { + Id = Qt::UserRole + 1, + Uuid, + Ip, + Port, + Mac, + Username, + Nickname, + System, + Platform, + Avatar, + RecentMsgContent, + RecentMsgTime, + UnreadMsgNum, + OnlineState, + Priority, + }; + + /*<"uuid" , QStandardItem *>*/ + QHash m_ItemsMap; + +private: + +}; + +#endif // FRIENDLISTMODEL_H \ No newline at end of file diff --git a/src/model/localinfomodel.cpp b/src/model/localinfomodel.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/model/localinfomodel.h b/src/model/localinfomodel.h new file mode 100644 index 0000000..e69de29 diff --git a/src/network/protocol_analysis.cpp b/src/network/protocol_analysis.cpp new file mode 100644 index 0000000..94bb149 --- /dev/null +++ b/src/network/protocol_analysis.cpp @@ -0,0 +1,133 @@ +#include "protocol_analysis.h" + +#include + +ProtocolAnalysis::ProtocolAnalysis() +{ + +} + +ProtocolAnalysis::~ProtocolAnalysis() +{ + +} + +QMap ProtocolAnalysis::analysisHeadBody(QString str) +{ + QMap dst; + QString key; + QString value; + dst.clear(); + key.clear(); + value.clear(); + + char *first = NULL; + char *separator = NULL; + char *end = NULL; + char *data = NULL; + char *tmp = NULL; + + if (str.isEmpty()) { + qDebug() << "Waring : ProtocolAnalysis , analysisHeadBody , orignal str is empty!!!"; + return dst; + } + + std::string originalStrTmp = str.toStdString(); + char *originalStr = const_cast(originalStrTmp.c_str()); + + /* 获取指向数据第一个字符的指针 */ + data = strstr(originalStr , "\r\n\r\n"); + if (data == NULL) { + qDebug() << "Error : ProtocolAnalysis , analysisHeadBody , package head error"; + return dst; + } + data = data + 4; + + /* 解析包头key */ + first = originalStr; + + while (first + 2 != data) { + separator = strchr(first , ':'); + end = strstr(first , "\r\n"); + + int size = separator - first + 1; + tmp = (char *)malloc(size); + memset(tmp , 0x00 , size); + + strncpy(tmp , first , separator - first); + + /* 保存key */ + key = QString(tmp); + + /* 解析value */ + size = end - separator; + tmp = (char *)realloc(tmp , size); + memset(tmp , 0x00 , size); + + strncpy(tmp , separator + 1 , end - separator - 1); + + /* 保存value */ + value = QString(tmp); + + /* 保存key , value */ + dst.insert(key , value); + + /* 释放堆内存 */ + free(tmp); + tmp = NULL; + + /* 重置first指针 */ + first = end + 2; + } + + /* 解析包体 */ + key = QString("body"); + value = QString(data); + + dst.insert(key , value); + + return dst; +} + +QString ProtocolAnalysis::encapsulationHeadBody(QMap map) +{ + + QString dst; + QString data; + + dst.clear(); + data.clear(); + + if (map.isEmpty()) { + qDebug() << "Waring : ProtocolAnalysis , encapsulationHeadBody , map is empty!!!"; + return dst; + } + + + data = map.value("body" , ""); + + /* 遍历map , 拼接包头 */ + QMap::iterator begin = map.begin(); + QMap::iterator end = map.end(); + + while (begin != end) { + QString key = begin.key(); + QString value = begin.value(); + + if (key != "body") { + dst.append(key); + dst.append(":"); + dst.append(value); + dst.append("\r\n"); + } + begin++; + } + + dst.append("\r\n"); + + if (!data.isEmpty()) { + dst.append(data); + } + + return dst; +} diff --git a/src/network/protocol_analysis.h b/src/network/protocol_analysis.h new file mode 100644 index 0000000..311d49b --- /dev/null +++ b/src/network/protocol_analysis.h @@ -0,0 +1,30 @@ +#ifndef __PROTOCOL_ANALYSIS_H__ +#define __PROTOCOL_ANALYSIS_H__ + +#include +#include + +class ProtocolAnalysis +{ +public: + ProtocolAnalysis(); + ~ProtocolAnalysis(); + + QMap analysisHeadBody(QString str); + QString encapsulationHeadBody(QMap map); + +private: +}; + +#endif + +/* + * 包头 + 包体 协议 + * uuid:xxx\r\n + * type:msg/file\r\n + * file_name:xx\r\n + * file_stat:info/data/end\r\n + * \r\n + * body + */ + diff --git a/src/network/tcp_client.cpp b/src/network/tcp_client.cpp new file mode 100644 index 0000000..9fd9f62 --- /dev/null +++ b/src/network/tcp_client.cpp @@ -0,0 +1,90 @@ +#include +#include + +#include "tcp_client.h" +#include "tcp_module.h" +#include "global/utils/global_data.h" + +TcpClient::TcpClient() +{ + +} + +TcpClient::~TcpClient() +{ + + +} + +int TcpClient::tran(g_send send) +{ + this->m_send = send; + + /* 检测链接是否建立 */ + g_tcpMaintain item = GlobalData::getInstance()->m_tcpLink.select(send.uuid); + + /* 链接已经建立 */ + if (item.module != NULL) { + if (send.type == QString("msg")) { + item.module->tranMsg(send); + + } else if (send.type == QString("file")) { + + } + + return 0; + } + + /* 链接未建立 */ + QString ip = item.peerListenIp; + QString port = item.peerListenPort; + + qDebug() << "Info : TcpClient , tran , connect peer ip ---> " << ip << "port ---> " << port; + + this->m_socket = new QTcpSocket; + connect(this->m_socket , &QTcpSocket::connected , this , &TcpClient::slotLinkSuccess); + this->m_socket->connectToHost(QHostAddress(ip) , port.toUShort() , QTcpSocket::ReadWrite); + + return 0; +} + +void TcpClient::slotLinkSuccess(void) +{ + qDebug() << "Info : TcpClient , slotLinkSuccess , client link success!!!"; + + /* 加载功能模块 */ + TcpModule *module = new TcpModule(this->m_socket , this->m_send); + + connect(module , &TcpModule::sigSendMsgSuccess , this , &TcpClient::slotSendMsgSuccess); + connect(module , &TcpModule::sigRecvMsgSuccess , this , &TcpClient::slotRecvMsgSuccess); + + /* 维护tcp链接表 */ + g_tcpItem item; + item.uuid = this->m_send.uuid; + item.selfIp = this->m_socket->localAddress().toString(); + item.selfPort = QString::number(this->m_socket->localPort()); + item.peerIp = this->m_socket->peerAddress().toString(); + item.peerPort = QString::number(this->m_socket->peerPort()); + item.module = module; + + if (GlobalData::getInstance()->m_tcpLink.tcpMaintainAdd(item)) { + qDebug() << "Error : TcpClient , slotLinkSuccess , maintain tcp link fail"; + } + + /* 移至线程中 */ + QThread *thread = new QThread; + module->moveToThread(thread); + thread->start(); + + return; +} + +void TcpClient::slotSendMsgSuccess(g_send send) +{ + emit sigTcpClientSendMsgSuccess(send); +} + +void TcpClient::slotRecvMsgSuccess(g_recv recv) +{ + emit sigTcpClientRecvMsgSuccess(recv); +} diff --git a/src/network/tcp_client.h b/src/network/tcp_client.h new file mode 100644 index 0000000..188ee05 --- /dev/null +++ b/src/network/tcp_client.h @@ -0,0 +1,33 @@ +#ifndef __TCP_CLIENT_H__ +#define __TCP_CLIENT_H__ + +#include +#include + +#include "global/declare/declare.h" + +class TcpClient : public QObject +{ + Q_OBJECT + +public: + TcpClient(); + ~TcpClient(); + + int tran(g_send send); + +private: + QTcpSocket *m_socket; + g_send m_send; + +signals: + void sigTcpClientSendMsgSuccess(g_send send); + void sigTcpClientRecvMsgSuccess(g_recv recv); + +private slots: + void slotLinkSuccess(void); + void slotSendMsgSuccess(g_send send); + void slotRecvMsgSuccess(g_recv recv); +}; + +#endif diff --git a/src/network/tcp_module.cpp b/src/network/tcp_module.cpp new file mode 100644 index 0000000..d0278a5 --- /dev/null +++ b/src/network/tcp_module.cpp @@ -0,0 +1,156 @@ +#include "global/utils/global_data.h" +#include "tcp_module.h" + +#include +#include + +/* 用于tcp server */ +TcpModule::TcpModule(QTcpSocket *socket) +{ + if (socket == NULL) { + qDebug() << "Error : TcpModule , call server , socket point is NULL"; + } + + this->m_flag = false; + this->m_uuid = ""; + this->m_socket = socket; + + establishInterrupt(); +} + +/* 重载构造 , 用于tcp client */ +TcpModule::TcpModule(QTcpSocket *socket , g_send send) +{ + if (socket == NULL) { + qDebug() << "Error : TcpModule , call client , socket point is NULL"; + } + + this->m_flag = true; + this->m_uuid = send.uuid; + this->m_socket = socket; + + establishInterrupt(); + + if (send.type == QString("msg")) { + tranMsg(send); + } else if (send.type == QString("file")) { + tranFile(send); + } +} + +TcpModule::~TcpModule() +{ + if (this->m_socket != NULL) { + delete m_socket; + } +} + +void TcpModule::establishInterrupt(void) +{ + connect(this->m_socket , &QTcpSocket::readyRead , this , &TcpModule::slotReadSocket); + connect(this->m_socket , &QTcpSocket::disconnected , this , &TcpModule::slotSocketDisconnect); + + return; +} + +void TcpModule::tranMsg(g_send send) +{ + /* 协议封装 */ + QMap map; + map.clear(); + map.insert(QString("uuid") , this->m_uuid); + map.insert(QString("type") , QString("msg")); + map.insert(QString("body") , send.msgData); + + QString encapsulationtData = moduleProtocolAnalysis.encapsulationHeadBody(map); + + /* 发送 */ + this->m_socket->write(encapsulationtData.toStdString().c_str()); + this->m_socket->flush(); + + qDebug() << "Info : TcpModule , tranMsg , success ---> " << send.msgData; + + /* 发送消息发送成功信号 */ + emit sigSendMsgSuccess(send); + + return; +} + +int TcpModule::tranFile(g_send send) +{ + +} + +void TcpModule::slotReadSocket(void) +{ + qDebug() << "Info : TcpModule , slotReadSocket , uuid ---> " << this->m_uuid; + + /* 接收数据包 */ + QByteArray recvData = this->m_socket->readAll(); + + /* 解析协议 */ + QMap map = moduleProtocolAnalysis.analysisHeadBody(QString(recvData)); + + /* 判断tcp module 是否可用 */ + if (m_flag == false) { + this->m_uuid = map.value(QString("uuid")); + if (this->m_uuid.isEmpty()) { + qDebug() << "Error : TcpModule , slotReadSocket , recvData uuid is empty , recv data discard"; + return; + } + + /* 维护tcp链接表 */ + g_tcpItem item; + item.uuid = this->m_uuid; + item.selfIp = GlobalData::getInstance()->m_tcpListenIP; + item.selfPort = GlobalData::getInstance()->m_tcpListenPort; + item.peerIp = this->m_socket->peerAddress().toString(); + item.peerPort = QString::number(this->m_socket->peerPort()); + item.module = this; + + /* 同步调用槽 , 接收返回值 */ + emit sigMaintainTcpLinkAdd(item); + + this->m_flag = true; + } + + /* 判断数据包是否对应 */ + if (map.value(QString("uuid")) != this->m_uuid) { + qDebug() << "Error : TcpModule , slotReadSocket , recv uuid differ save uuid , recv data discard"; + return; + } + + /* 判断数据包种类 */ + if (map.value(QString("type")) == QString("msg")) { + /* 接收信息 */ + g_recv recv; + recv.uuid = this->m_uuid; + recv.type = QString("msg"); + recv.msgData = map.value(QString("body")); + + /* ---临时打印--- */ + qDebug() << "Info : TcpModule , slotReadSocket , recv msg ---> " << recv.msgData; + + emit sigRecvMsgSuccess(recv); + + } else if (map.value(QString("type")) == QString("file")) { + /* 接收文件 */ + + } + + return; +} + +void TcpModule::slotSocketDisconnect(void) +{ + /* 释放socket */ + if (this->m_socket != NULL) { + delete this->m_socket; + this->m_socket = NULL; + } + + /* 维护tcp链接表 */ + emit sigMaintainTcpLinkDelete(this->m_uuid); + + return; +} diff --git a/src/network/tcp_module.h b/src/network/tcp_module.h new file mode 100644 index 0000000..f468b3a --- /dev/null +++ b/src/network/tcp_module.h @@ -0,0 +1,45 @@ +#ifndef __TCP_MODULE_H__ +#define __TCP_MODULE_H__ + +#include "global/declare/declare.h" +#include "protocol_analysis.h" + +#include +#include + +class TcpModule : public QObject +{ + Q_OBJECT + +public: + TcpModule(QTcpSocket *socket); + TcpModule(QTcpSocket *socket , g_send send); + ~TcpModule(); + + int tranFile(g_send send); + void tranMsg(g_send send); + +public: + ProtocolAnalysis moduleProtocolAnalysis; + +private: + void establishInterrupt(void); + +private: + bool m_flag; + QString m_uuid; + QTcpSocket *m_socket; + +signals: + void sigMaintainTcpLinkAdd(g_tcpItem item); + void sigMaintainTcpLinkDelete(QString uuid); + void sigSendMsgSuccess(g_send send); + void sigRecvMsgSuccess(g_recv recv); + +private slots: + void slotReadSocket(void); + void slotSocketDisconnect(void); + +}; + +#endif diff --git a/src/network/tcp_server.cpp b/src/network/tcp_server.cpp new file mode 100644 index 0000000..47c3680 --- /dev/null +++ b/src/network/tcp_server.cpp @@ -0,0 +1,98 @@ +#include "tcp_server.h" +#include "global/utils/global_data.h" +#include "tcp_module.h" + +#include +#include +#include + +TcpServer::TcpServer() +{ + qDebug() << "Info : TcpServer , tcp server start up ..."; + establishInterrupt(); + startListen(); +} + +TcpServer::~TcpServer() +{ + +} + +void TcpServer::establishInterrupt(void) +{ + connect(this , &TcpServer::newConnection , this , &TcpServer::slotEstablishNewLink); + + return; +} + +int TcpServer::startListen(void) +{ + /* 获取需要监听的ip和port */ + QString ip = GlobalData::getInstance()->m_tcpListenIP; + QString port = GlobalData::getInstance()->m_tcpListenPort; + + if (ip.isEmpty() || port.isEmpty()) { + qDebug() << "Error : TcpServer , startListen , ip or port is empty"; + return -1; + } + + if (this->listen(QHostAddress(ip) , port.toUShort()) == false) { + qDebug() << "Error : TcpServer , startListen , listen fail"; + return -1; + } + + qDebug() << "Info : TcpServer , startListen , listen success , ip --- > " << ip << "port ---> " << port; + + return 0; +} + +void TcpServer::slotEstablishNewLink(void) +{ + qDebug() << "Info : TcpServer , slotEstablishNewLink , new link coming in ..."; + + /* 获取新链接 */ + QTcpSocket *socket = this->nextPendingConnection(); + + /* 加载功能模块 */ + TcpModule *tcpModule = new TcpModule(socket); + + connect(tcpModule , &TcpModule::sigMaintainTcpLinkAdd , this , &TcpServer::slotMaintainTcpLinkAdd , Qt::BlockingQueuedConnection); + connect(tcpModule , &TcpModule::sigMaintainTcpLinkDelete , this , &TcpServer::slotMaintainTcpLinkDelete , Qt::BlockingQueuedConnection); + connect(tcpModule , &TcpModule::sigRecvMsgSuccess , this , &TcpServer::slotRecvMsgSuccess , Qt::BlockingQueuedConnection); + connect(tcpModule , &TcpModule::sigSendMsgSuccess , this , &TcpServer::slotSendMsgSuccess , Qt::BlockingQueuedConnection); + + /* 移至线程 */ + QThread *thread = new QThread; + tcpModule->moveToThread(thread); + thread->start(); + + return; +} + +void TcpServer::slotMaintainTcpLinkAdd(g_tcpItem item) +{ + qDebug() << "Info : TcpServer , slotMaintainTcpLinkAdd , uuid ---> " << item.uuid; + + if (GlobalData::getInstance()->m_tcpLink.tcpMaintainAdd(item)) { + qDebug() << "Waring , TcpServer , slotMaintainTcpLinkadd , maintain tcp link fail"; + } +} + +void TcpServer::slotMaintainTcpLinkDelete(QString uuid) +{ + qDebug() << "Info : TcpServer , slotMaintainTcpLinkDelete , uuid ---> " << uuid; + + if (GlobalData::getInstance()->m_tcpLink.tcpMaintainDelete(uuid)) { + qDebug() << "Waring , TcpServer , slotMaintainTcpLinkDelete , maintain tcp link fail"; + } +} + +void TcpServer::slotRecvMsgSuccess(g_recv recv) +{ + emit sigTcpServerRecvMsgSuccess(recv); +} + +void TcpServer::slotSendMsgSuccess(g_send send) +{ + emit sigTcpServerSendMsgSuccess(send); +} diff --git a/src/network/tcp_server.h b/src/network/tcp_server.h new file mode 100644 index 0000000..52a6576 --- /dev/null +++ b/src/network/tcp_server.h @@ -0,0 +1,34 @@ +#ifndef __TCP_SERVER_H__ +#define __TCP_SERVER_H__ + +#include +#include + +#include "global/declare/declare.h" + +class TcpServer : public QTcpServer +{ + Q_OBJECT + +public: + TcpServer(); + ~TcpServer(); + +private: + void establishInterrupt(void); + int startListen(void); + +/* 对外模块信号 */ +signals: + void sigTcpServerRecvMsgSuccess(g_recv recv); + void sigTcpServerSendMsgSuccess(g_send send); + +private slots: + void slotEstablishNewLink(void); + void slotRecvMsgSuccess(g_recv recv); + void slotSendMsgSuccess(g_send send); + void slotMaintainTcpLinkAdd(g_tcpItem item); + void slotMaintainTcpLinkDelete(QString uuid); +}; + +#endif diff --git a/src/network/udp_socket.cpp b/src/network/udp_socket.cpp new file mode 100644 index 0000000..aa0c775 --- /dev/null +++ b/src/network/udp_socket.cpp @@ -0,0 +1,150 @@ +#include "udp_socket.h" +#include "global/utils/global_data.h" + +#include + +UdpSocket::UdpSocket() +{ + init(); + //slotOnline(); +} + +UdpSocket::~UdpSocket() +{ + if (this->m_timer != NULL) { + delete this->m_timer; + } + + if (this->m_udpSocket != NULL) { + delete this->m_udpSocket; + } + + slotOffline(); +} + +void UdpSocket::init(void) +{ + /* 实例udpsocket */ + this->m_udpSocket = new QUdpSocket; + + /* 获取udp监听端口 */ + QString port = GlobalData::getInstance()->m_udpListenPort; + + if (this->m_udpSocket->bind(QHostAddress::AnyIPv4 , port.toUShort() , QUdpSocket::ReuseAddressHint) == true) { + qDebug() << "Info : UdpSocket , bind success"; + } + + connect(this->m_udpSocket , &QUdpSocket::readyRead , this , &UdpSocket::slotSocketRead); + + /* 启动定时器 */ + this->m_timer = new QTimer; + connect(this->m_timer , &QTimer::timeout , this , &UdpSocket::slotOnline); + this->m_timer->start(10000); + + return; +} + +void UdpSocket::slotSocketRead(void) +{ + qDebug() << "Info , UdpSocket , slotSocketRead , recv udp package"; + + while (this->m_udpSocket->hasPendingDatagrams()) { + QByteArray package; + package.resize(65536); + QHostAddress peerIp; + int size = this->m_udpSocket->readDatagram(package.data() , package.size() , &peerIp); + package.resize(size); + + /* udp包接收完毕 , 解析udp包 */ + QString data = QString::fromUtf8(package); + QStringList dataList = data.split(" "); + if (dataList.at(0) == "true") { + /* 上线广播 */ + QString uuid = dataList.at(1); + QString peerListenIp = dataList.at(2); + QString peerListenPort = dataList.at(3); + + /* 维护tcp链接表 */ + g_udpItem tmp; + tmp.uuid = uuid; + tmp.peerListenIp = peerListenIp; + tmp.peerListenPort = peerListenPort; + + GlobalData::getInstance()->m_tcpLink.udpMaintainAdd(tmp); + + /* 测试输出 */ + qDebug() << "Info : UdpSocket , slotUdpSocketRead , recv udp data"; + qDebug() << "uuid = " << uuid << "peerListenIp = " << peerListenIp << "peerListenPort = " << peerListenPort; + GlobalData::getInstance()->m_tcpLink.ergodic(); + } else if (dataList.at(0) == "false") { + QString uuid = dataList.at(1); + + /* 维护tcp链接表 */ + GlobalData::getInstance()->m_tcpLink.udpMaintainDelete(uuid); + GlobalData::getInstance()->m_tcpLink.ergodic(); + + qDebug() << "Info : UdpSocket , slotUdpSocketRead , recv udp offline"; + } + } + + return; +} + +void UdpSocket::udpSocketBroadcast(bool flag) +{ + QByteArray package; + QString udpListenPort = GlobalData::getInstance()->m_udpListenPort; + + /* 组装数据包 */ + QString uuid = GlobalData::getInstance()->m_uuid; + QString tcpListenIp = GlobalData::getInstance()->m_tcpListenIP; + QString tcpListenPort = GlobalData::getInstance()->m_tcpListenPort; + + if (flag == true) { + package.append(QString("true")); + package.append(QString(" ")); + package.append(uuid); + package.append(QString(" ")); + package.append(tcpListenIp); + package.append(QString(" ")); + package.append(tcpListenPort); + } else { + package.append(QString("false")); + package.append(QString(" ")); + package.append(QString(uuid)); + } + + /* 广播发送 */ + QList interface = QNetworkInterface::allInterfaces(); + for (int i = 0 ; i < interface.count() ; i++) { + QList addrs = interface.at(i).addressEntries(); + + for (int j = 0 ; j < addrs.count() ; j++) { + if (addrs.at(j).ip().protocol() == QAbstractSocket::IPv4Protocol && (addrs.at(j).broadcast().toString() != "")) { + this->m_udpSocket->writeDatagram(package.data() , package.length() , addrs.at(j).broadcast() , udpListenPort.toUShort()); + + qDebug() << "Debug : UdpSocket , udpSocketBroadcast , broadcast addr ---> " << addrs.at(j).broadcast(); + + this->m_udpSocket->flush(); + } + } + } + + qDebug() << "Info : UdpSocket , udpSocketBroadcast , udp pkg ---> " << package; + + return; +} + +void UdpSocket::slotOnline(void) +{ + udpSocketBroadcast(true); + + return; +} + +void UdpSocket::slotOffline(void) +{ + udpSocketBroadcast(false); + + return; +} diff --git a/src/network/udp_socket.h b/src/network/udp_socket.h new file mode 100644 index 0000000..b63c12f --- /dev/null +++ b/src/network/udp_socket.h @@ -0,0 +1,27 @@ +#ifndef __UDP_SOCKET_H__ +#define __UDP_SOCKET_H__ + +#include +#include + +class UdpSocket : public QObject +{ +public: + UdpSocket(); + ~UdpSocket(); + +private: + QUdpSocket *m_udpSocket; + QTimer *m_timer; + +private: + void init(void); + void udpSocketBroadcast(bool flag); + +private slots: + void slotSocketRead(void); + void slotOnline(void); + void slotOffline(void); +}; + +#endif diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..1a2ba64 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,88 @@ +QT += core gui network dbus sql +QT += x11extras KWindowSystem + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +QMAKE_CXXFLAGS += -g + +# 适配窗口管理器圆角阴影 +LIBS +=-lpthread +LIBS +=-lX11 + +# 配置gsettings +CONFIG += link_pkgconfig +PKGCONFIG += gsettings-qt + +# for nullptr +CONFIG += c++11 + +# 配置gsettings +PKGCONFIG += gsettings-qt + +# 统一日志输出 +#LIBS += -L/usr/lib/libukui-log4qt.so.1.0.0 -lukui-log4qt + +TARGET = kylin-messages +TEMPLATE = app + +DEFINES += QT_DEPRECATED_WARNINGS + +target.path = /usr/bin +target.source += $$TARGET + +INSTALLS += target + +# V10Pro使用自定义用户手册 +greaterThan(QT_MAJOR_VERSION, 5) | greaterThan(QT_MINOR_VERSION, 9) { + # message("QT_VERSION ("$$QT_VERSION")") + DEFINES += __V10Pro__ +} + +SOURCES += \ + $$PWD/main.cpp \ + $$PWD/view/kyview.cpp \ + $$PWD/view/common/xatom-helper.cpp \ + $$PWD/view/common/daemondbus.cpp \ + $$PWD/view/common/dbusadaptor.cpp \ + $$PWD/view/common/globalsizedata.cpp\ + $$PWD/view/titlebar/menumodule.cpp \ + $$PWD/view/titlebar/titlebar.cpp \ + $$PWD/view/localinfo/localinfo.cpp \ + $$PWD/view/friendlist/friendlist.cpp\ + $$PWD/view/friendlist/friendItemDelegate.cpp \ + $$PWD/model/friendlistmodel.cpp \ + $$PWD/global/database/database.cpp \ + $$PWD/global/utils/global_data.cpp \ + $$PWD/global/utils/tcp_link.cpp \ + $$PWD/network/protocol_analysis.cpp \ + $$PWD/network/tcp_client.cpp \ + $$PWD/network/tcp_module.cpp \ + $$PWD/network/tcp_server.cpp \ + $$PWD/network/udp_socket.cpp \ + controller/control.cpp + +HEADERS += \ + $$PWD/view/kyview.h \ + $$PWD/view/common/xatom-helper.h \ + $$PWD/view/common/daemondbus.h \ + $$PWD/view/common/dbusadaptor.h \ + $$PWD/view/common/globalsizedata.h \ + $$PWD/view/titlebar/menumodule.h \ + $$PWD/view/titlebar/titlebar.h \ + $$PWD/view/localinfo/localinfo.h \ + $$PWD/view/friendlist/friendlist.h \ + $$PWD/view/friendlist/friendItemDelegate.h \ + $$PWD/model/friendlistmodel.h \ + $$PWD/view/common/dbusadaptor.h \ + $$PWD/global/database/database.h \ + $$PWD/global/declare/declare.h \ + $$PWD/global/utils/global_data.h \ + $$PWD/global/utils/tcp_link.h \ + $$PWD/network/protocol_analysis.h \ + $$PWD/network/tcp_client.h \ + $$PWD/network/tcp_module.h \ + $$PWD/network/tcp_server.h \ + $$PWD/network/udp_socket.h \ + controller/control.h + +RESOURCES += \ diff --git a/daemonipcdbus.cpp b/src/view/common/daemondbus.cpp similarity index 71% rename from daemonipcdbus.cpp rename to src/view/common/daemondbus.cpp index 1ff220a..a87a068 100644 --- a/daemonipcdbus.cpp +++ b/src/view/common/daemondbus.cpp @@ -1,64 +1,73 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "daemonipcdbus.h" - -int DaemonIpcDbus::daemonIsNotRunning() -{ - char service_name[SERVICE_NAME_SIZE]; - memset(service_name, 0, SERVICE_NAME_SIZE); - snprintf(service_name, SERVICE_NAME_SIZE, "%s_%d",KYLIN_USER_GUIDE_SERVICE,getuid()); - QDBusConnection conn = QDBusConnection::sessionBus(); - if (!conn.isConnected()) - return -1; - - QDBusReply reply = conn.interface()->call("GetNameOwner", service_name); - return reply.value() == ""; -} - -void DaemonIpcDbus::showGuide(QString appName) -{ - qDebug() << Q_FUNC_INFO << appName; - bool bRet = false; - - char service_name[SERVICE_NAME_SIZE]; - memset(service_name, 0, SERVICE_NAME_SIZE); - snprintf(service_name, SERVICE_NAME_SIZE, "%s_%d",KYLIN_USER_GUIDE_SERVICE,getuid()); - - qDebug() << "service_name " << service_name; - // 用来构造一个在D-Bus上传递的Message - QDBusMessage m = QDBusMessage::createMethodCall(QString(service_name),KYLIN_USER_GUIDE_PATH,KYLIN_USER_GUIDE_INTERFACE,"showGuide"); - // 给QDBusMessage增加一个参数; - // 这是一种比较友好的写法,也可以用setArguments来实现 - m << appName; - - // 发送Message - QDBusMessage response = QDBusConnection::sessionBus().call(m); - // 判断Method是否被正确返回 - if (response.type()== QDBusMessage::ReplyMessage) - { - // QDBusMessage的arguments不仅可以用来存储发送的参数,也用来存储返回值; -// bRet = response.arguments().at(0).toBool(); - } - else { - qDebug()<<"showGuide In fail!\n"; - } - - qDebug()<<"bRet:"<. + */ + +#include "daemondbus.h" + +// 生成静态实例 +DaemonDbus *DaemonDbus::getInstance() +{ + static DaemonDbus *instance = nullptr; + if (nullptr == instance) { + instance = new DaemonDbus(); + } + return instance; +} + +int DaemonDbus::daemonIsNotRunning() +{ + char service_name[SERVICE_NAME_SIZE]; + memset(service_name, 0, SERVICE_NAME_SIZE); + snprintf(service_name, SERVICE_NAME_SIZE, "%s_%d",KYLIN_USER_GUIDE_SERVICE,getuid()); + QDBusConnection conn = QDBusConnection::sessionBus(); + if (!conn.isConnected()) + return -1; + + QDBusReply reply = conn.interface()->call("GetNameOwner", service_name); + return reply.value() == ""; +} + +void DaemonDbus::showGuide(QString appName) +{ + qDebug() << Q_FUNC_INFO << appName; + bool bRet = false; + + char service_name[SERVICE_NAME_SIZE]; + memset(service_name, 0, SERVICE_NAME_SIZE); + snprintf(service_name, SERVICE_NAME_SIZE, "%s_%d",KYLIN_USER_GUIDE_SERVICE,getuid()); + + qDebug() << "service_name " << service_name; + // 构造一个在D-Bus上传递的Message + QDBusMessage m = QDBusMessage::createMethodCall(QString(service_name),KYLIN_USER_GUIDE_PATH,KYLIN_USER_GUIDE_INTERFACE,"showGuide"); + // 给QDBusMessage增加一个参数; + // 这是一种比较友好的写法,也可以用setArguments来实现 + m << appName; + + // 发送Message + QDBusMessage response = QDBusConnection::sessionBus().call(m); + // 判断Method是否被正确返回 + if (response.type()== QDBusMessage::ReplyMessage) + { + // QDBusMessage的arguments不仅可以用来存储发送的参数,也用来存储返回值; + //bRet = response.arguments().at(0).toBool(); + } + else { + qDebug()<<"showGuide In fail!\n"; + } + + qDebug()<<"bRet:"< -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class DaemonIpcDbus : public QObject -{ - Q_OBJECT - // 定义Interface名称为com.scorpio.test.value -// Q_CLASSINFO("D-Bus Interface", "com.scorpio.test.value") -public: - - DaemonIpcDbus() {} - -public slots: - - int daemonIsNotRunning(); - void showGuide(QString appName); - -}; - -/* -// 使用方法 -DaemonIpcDbus *mDaemonIpcDbus; -mDaemonIpcDbus = new DaemonIpcDbus(); -if (!mDaemonIpcDbus->daemonIsNotRunning()){ - //增加标题栏帮助菜单、F1快捷键打开用户手册 - mDaemonIpcDbus->showGuide("kylin-ipmsg"); -} -*/ - -#endif // DAEMONIPCDBUS_H +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DAEMONIPCDBUS_H +#define DAEMONIPCDBUS_H + +#define KYLIN_USER_GUIDE_PATH "/" + +#define KYLIN_USER_GUIDE_SERVICE "com.kylinUserGuide.hotel" + +#define KYLIN_USER_GUIDE_INTERFACE "com.guide.hotel" + +#define SERVICE_NAME_SIZE 30 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class DaemonDbus : public QObject +{ + Q_OBJECT + // 定义Interface名称为com.scorpio.test.value + // Q_CLASSINFO("D-Bus Interface", "com.scorpio.test.value") +public: + + DaemonDbus() {} + + // 生成静态实例 + static DaemonDbus *getInstance(); + +public slots: + + int daemonIsNotRunning(); + void showGuide(QString appName); + +}; + +/* +// 使用方法 +if (!DaemonDbus::getInstance()->daemonIsNotRunning()){ + //增加标题栏帮助菜单、F1快捷键打开用户手册 + DaemonDbus::getInstance()->showGuide("kylin-ipmsg"); +} +*/ + +#endif // DAEMONIPCDBUS_H + diff --git a/src/view/common/dbusadaptor.cpp b/src/view/common/dbusadaptor.cpp new file mode 100644 index 0000000..2b5f2a9 --- /dev/null +++ b/src/view/common/dbusadaptor.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "dbusadaptor.h" + +DbusAdaptor::DbusAdaptor(QObject *parent) + : QObject(parent) +{ + QDBusConnection connection = QDBusConnection::sessionBus(); + if (!connection.registerService(KYLIN_MESSAGES_SERVICE)) { + return ; + } + connection.registerObject(KYLIN_MESSAGES_PATH, this, QDBusConnection::ExportAllSlots); +} + +DbusAdaptor::~DbusAdaptor() +{ +} + +// 显示应用主界面 +void DbusAdaptor::showMainWindow() +{ + qDebug() << "showMainWindow"; + KyView::getInstance()->pullUpWindow(); +} + diff --git a/src/view/common/dbusadaptor.h b/src/view/common/dbusadaptor.h new file mode 100644 index 0000000..ee70b44 --- /dev/null +++ b/src/view/common/dbusadaptor.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DBUSADAPTOR_H +#define DBUSADAPTOR_H + +#define KYLIN_MESSAGES_PATH "/" +#define KYLIN_MESSAGES_SERVICE "com.kylin.messages" +#define KYLIN_MESSAGES_INTERFACE "com.kylin.messages" + +#include +#include +#include +#include +#include +#include +#include + +#include "../kyview.h" + +class DbusAdaptor: public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", KYLIN_MESSAGES_SERVICE) + +public: + DbusAdaptor(QObject *parent = 0); + virtual ~DbusAdaptor(); + +public slots: + // 显示应用主界面 + void showMainWindow(); +}; + +#endif diff --git a/src/view/common/globalsizedata.cpp b/src/view/common/globalsizedata.cpp new file mode 100644 index 0000000..b99f830 --- /dev/null +++ b/src/view/common/globalsizedata.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "globalsizedata.h" + +// 主界面 +const int GlobalSizeData::WINDOW_WIDTH = 350; +const int GlobalSizeData::WINDOW_HEIGHT = 686; + +// 标题栏 +const int GlobalSizeData::TITLEBAR_HEIGHT = 40; + +// 本机信息 +const int GlobalSizeData::LOCALINFO_HEIGHT = 140; +const QSize GlobalSizeData::AVATAR_LAB_SIZE = QSize(60, 60); +const QSize GlobalSizeData::USER_NAME_LAB_SIZE = QSize(90, 20); +const QSize GlobalSizeData::USER_IP_LAB_SIZE = QSize(170, 20); +const QSize GlobalSizeData::CHANGE_NAME_BTN_SIZE = QSize(25, 25); +const QSize GlobalSizeData::CHANGE_NAME_BTN_ICON = QSize(16, 16); +const QSize GlobalSizeData::OPEN_FOLDER_BTN_SIZE = QSize(25, 25); +const QSize GlobalSizeData::OPEN_FOLDER_BTN_ICON = QSize(16, 16); +const QSize GlobalSizeData::SEARCH_EDIT_SIZE = QSize(334, 36); + +// 好友列表 +const int GlobalSizeData::FRIEND_LIST_HEIGHT = 506; \ No newline at end of file diff --git a/src/view/common/globalsizedata.h b/src/view/common/globalsizedata.h new file mode 100644 index 0000000..94d0ad5 --- /dev/null +++ b/src/view/common/globalsizedata.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GLOBALSIZEDATA_H +#define GLOBALSIZEDATA_H + +#include +#include +#include + +class GlobalSizeData +{ +public: + // 主界面 + static const int WINDOW_WIDTH; //主界面宽度 + static const int WINDOW_HEIGHT; //主界面高度 + + // 标题栏 + static const int TITLEBAR_HEIGHT; //标题栏高度 + + // 本机信息 + static const int LOCALINFO_HEIGHT; //本机信息高度 + static const QSize AVATAR_LAB_SIZE; // 本机头像尺寸 + static const QSize USER_NAME_LAB_SIZE; // 本机昵称尺寸 + static const QSize USER_IP_LAB_SIZE; // 本机IP尺寸 + static const QSize CHANGE_NAME_BTN_SIZE;// 修改本机昵称按钮 + static const QSize CHANGE_NAME_BTN_ICON;// 修改本机昵称按钮图标 + static const QSize OPEN_FOLDER_BTN_SIZE;// 打开文件保存目录按钮 + static const QSize OPEN_FOLDER_BTN_ICON;// 打开文件保存目录按钮图标 + static const QSize SEARCH_EDIT_SIZE; // 打开文件保存目录按钮 + static const QSize SEARCH_EDIT_ICON; // 打开文件保存目录按钮图标 + + // 好友列表 + static const int FRIEND_LIST_HEIGHT; //好友列表高度 + +}; + +#endif // GLOBALSIZEDATA_H \ No newline at end of file diff --git a/src/view/common/xatom-helper.cpp b/src/view/common/xatom-helper.cpp new file mode 100644 index 0000000..c2682fe --- /dev/null +++ b/src/view/common/xatom-helper.cpp @@ -0,0 +1,216 @@ +/* + * KWin Style UKUI + * + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: Yue Lan + * + */ + +#include "xatom-helper.h" + +#include + +#include + +#include +#include +#include +#include + +static XAtomHelper *global_instance = nullptr; + +XAtomHelper *XAtomHelper::getInstance() +{ + if (!global_instance) + global_instance = new XAtomHelper; + return global_instance; +} + +bool XAtomHelper::isFrameLessWindow(int winId) +{ + auto hints = getInstance()->getWindowMotifHint(winId); + if (hints.flags == MWM_HINTS_DECORATIONS && hints.functions == 1) { + return true; + } + return false; +} + +bool XAtomHelper::isWindowDecorateBorderOnly(int winId) +{ + return isWindowMotifHintDecorateBorderOnly(getInstance()->getWindowMotifHint(winId)); +} + +bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint) +{ + bool isDeco = false; + if (hint.flags & MWM_HINTS_DECORATIONS && hint.flags != MWM_HINTS_DECORATIONS) { + if (hint.decorations == MWM_DECOR_BORDER) + isDeco = true; + } + return isDeco; +} + +bool XAtomHelper::isUKUICsdSupported() +{ + // fixme: + return false; +} + +bool XAtomHelper::isUKUIDecorationWindow(int winId) +{ + if (m_ukuiDecorationAtion == None) + return false; + + unsigned long type; + int format; + ulong nitems; + ulong bytes_after; + uchar *data; + + bool isUKUIDecoration = false; + + XGetWindowProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, + 0, LONG_MAX, false, + m_ukuiDecorationAtion, &type, + &format, &nitems, + &bytes_after, &data); + + if (type == m_ukuiDecorationAtion) { + if (nitems == 1) { + isUKUIDecoration = data[0]; + } + } + + return isUKUIDecoration; +} + +UnityCorners XAtomHelper::getWindowBorderRadius(int winId) +{ + UnityCorners corners; + + Atom type; + int format; + ulong nitems; + ulong bytes_after; + uchar *data; + + if (m_unityBorderRadiusAtom != None) { + XGetWindowProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, + 0, LONG_MAX, false, + XA_CARDINAL, &type, + &format, &nitems, + &bytes_after, &data); + + if (type == XA_CARDINAL) { + if (nitems == 4) { + corners.topLeft = static_cast(data[0]); + corners.topRight = static_cast(data[1*sizeof (ulong)]); + corners.bottomLeft = static_cast(data[2*sizeof (ulong)]); + corners.bottomRight = static_cast(data[3*sizeof (ulong)]); + } + XFree(data); + } + } + + return corners; +} + +void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data) +{ + if (m_unityBorderRadiusAtom == None) + return; + + ulong corners[4] = {data.topLeft, data.topRight, data.bottomLeft, data.bottomRight}; + + XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, + 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); +} + +void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight) +{ + if (m_unityBorderRadiusAtom == None) + return; + + ulong corners[4] = {(ulong)topLeft, (ulong)topRight, (ulong)bottomLeft, (ulong)bottomRight}; + + XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, + 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); +} + +void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set) +{ + if (m_ukuiDecorationAtion == None) + return; + + XChangeProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, m_ukuiDecorationAtion, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &set, 1); +} + +void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints) +{ + if (m_unityBorderRadiusAtom == None) + return; + + XChangeProperty(QX11Info::display(), winId, m_motifWMHintsAtom, m_motifWMHintsAtom, + 32, XCB_PROP_MODE_REPLACE, (const unsigned char *)&hints, sizeof (MotifWmHints)/ sizeof (ulong)); +} + +MotifWmHints XAtomHelper::getWindowMotifHint(int winId) +{ + MotifWmHints hints; + + if (m_unityBorderRadiusAtom == None) + return hints; + + uchar *data; + Atom type; + int format; + ulong nitems; + ulong bytes_after; + + XGetWindowProperty(QX11Info::display(), winId, m_motifWMHintsAtom, + 0, sizeof (MotifWmHints)/sizeof (long), false, AnyPropertyType, &type, + &format, &nitems, &bytes_after, &data); + + if (type == None) { + return hints; + } else { + hints = *(MotifWmHints *)data; + XFree(data); + } + return hints; +} + +XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent) +{ + if (!QX11Info::isPlatformX11()) + return; + + m_motifWMHintsAtom = XInternAtom(QX11Info::display(), "_MOTIF_WM_HINTS", true); + m_unityBorderRadiusAtom = XInternAtom(QX11Info::display(), "_UNITY_GTK_BORDER_RADIUS", false); + m_ukuiDecorationAtion = XInternAtom(QX11Info::display(), "_KWIN_UKUI_DECORAION", false); +} + +Atom XAtomHelper::registerUKUICsdNetWmSupportAtom() +{ + // fixme: + return None; +} + +void XAtomHelper::unregisterUKUICsdNetWmSupportAtom() +{ + // fixme: +} diff --git a/src/view/common/xatom-helper.h b/src/view/common/xatom-helper.h new file mode 100644 index 0000000..d4923cc --- /dev/null +++ b/src/view/common/xatom-helper.h @@ -0,0 +1,111 @@ +/* + * KWin Style UKUI + * + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: Yue Lan + * + */ + +#ifndef XATOMHELPER_H +#define XATOMHELPER_H + +#include + +#include +#include + +struct UnityCorners { + ulong topLeft = 0; + ulong topRight = 0; + ulong bottomLeft = 0; + ulong bottomRight = 0; +}; + +typedef struct { + ulong flags = 0; + ulong functions = 0; + ulong decorations = 0; + long input_mode = 0; + ulong status = 0; +} MotifWmHints, MwmHints; + +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_INPUT_MODE (1L << 2) +#define MWM_HINTS_STATUS (1L << 3) + +#define MWM_FUNC_ALL (1L << 0) +#define MWM_FUNC_RESIZE (1L << 1) +#define MWM_FUNC_MOVE (1L << 2) +#define MWM_FUNC_MINIMIZE (1L << 3) +#define MWM_FUNC_MAXIMIZE (1L << 4) +#define MWM_FUNC_CLOSE (1L << 5) + +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) + +#define MWM_INPUT_MODELESS 0 +#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 +#define MWM_INPUT_SYSTEM_MODAL 2 +#define MWM_INPUT_FULL_APPLICATION_MODAL 3 +#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL + +#define MWM_TEAROFF_WINDOW (1L<<0) + +namespace UKUI { +class Decoration; +} + +class XAtomHelper : public QObject +{ + friend class UKUI::Decoration; + Q_OBJECT +public: + static XAtomHelper *getInstance(); + + static bool isFrameLessWindow(int winId); + + bool isWindowDecorateBorderOnly(int winId); + bool isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint); + bool isUKUICsdSupported(); + bool isUKUIDecorationWindow(int winId); + + UnityCorners getWindowBorderRadius(int winId); + void setWindowBorderRadius(int winId, const UnityCorners &data); + void setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight); + void setUKUIDecoraiontHint(int winId, bool set = true); + + void setWindowMotifHint(int winId, const MotifWmHints &hints); + MotifWmHints getWindowMotifHint(int winId); + +private: + explicit XAtomHelper(QObject *parent = nullptr); + + unsigned long registerUKUICsdNetWmSupportAtom(); + void unregisterUKUICsdNetWmSupportAtom(); + + unsigned long m_motifWMHintsAtom = 0; + unsigned long m_unityBorderRadiusAtom = 0; + unsigned long m_ukuiDecorationAtion = 0; +}; + +#endif // XATOMHELPER_H diff --git a/src/view/friendlist/friendItemDelegate.cpp b/src/view/friendlist/friendItemDelegate.cpp new file mode 100644 index 0000000..1abeb60 --- /dev/null +++ b/src/view/friendlist/friendItemDelegate.cpp @@ -0,0 +1,137 @@ + + +#include "friendItemDelegate.h" + +FriendItemDelegate::FriendItemDelegate() +{ +} + +FriendItemDelegate::~FriendItemDelegate() +{ +} + +QSize FriendItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + Q_UNUSED(index) + return QSize(350, 70); +} + +void FriendItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + if (index.isValid()) { + // QPainter *savePainter = new QPainter(); + // savePainter = painter; + painter->save(); + + // 反锯齿 + painter->setRenderHint(QPainter::Antialiasing); + + // 获取数据 + QString avatar = index.data(FriendListModel::Avatar).toString(); + QString nickname = index.data(FriendListModel::Nickname).toString(); + QString msgContent = index.data(FriendListModel::RecentMsgContent).toString(); + QString msgTime = index.data(FriendListModel::RecentMsgTime).toString(); + QString msgNum = index.data(FriendListModel::UnreadMsgNum).toString(); + + // item 矩形区域 + QRectF itemRect; + itemRect.setX(option.rect.x()); + itemRect.setY(option.rect.y()); + itemRect.setWidth(option.rect.width() - 1); + itemRect.setHeight(option.rect.height() - 1); + + QPainterPath path; + // 鼠标悬停或者选中时改变背景色 + if (option.state.testFlag(QStyle::State_MouseOver)) { + // painter->setPen(QPen(QColor("#ebeced"))); + path.setFillRule( Qt::WindingFill ); //设置填充方式 + path.addRoundedRect(itemRect, 0, 0); + painter->fillPath(path, QBrush(QColor("#EBEBEB"))); + } + + // 好友头像 + QPoint avatarPoint(itemRect.left() + 16, itemRect.top() + 10); + QSize avatarSize(50, 50); + QRectF avatarRect = QRect(avatarPoint, avatarSize); + // 画圆 + QPainterPath avatarPath; + avatarPath.setFillRule( Qt::WindingFill ); //设置填充方式 + avatarPath.addRoundedRect(avatarRect, 30, 30); + painter->fillPath(avatarPath, QBrush(QColor(55, 144, 250))); + + // // 设置背景色 + // painter->setBrush(Qt::blue); + // painter->drawRect(avatarRect); + + // 好友昵称或备注 + QPoint nicknamePoint(avatarRect.right() + 8, itemRect.top() + 10); + QSize nicknameSize(170, 25); + QRectF nicknameRect = QRect(nicknamePoint, nicknameSize); + + // 最近聊天内容 + QPoint contentPoint(avatarRect.right() + 8, itemRect.bottom() - 34); + QSize contentSize(186, 20); + QRectF contentRect = QRect(contentPoint, contentSize); + // contentRect.setBottom(itemRect.bottom() - 16); + + // 最近聊天时间 + QPoint timePoint(itemRect.right() - 80, itemRect.top() + 10); + QSize timeSize(60, 20); + QRectF timeRect = QRect(timePoint, timeSize); + timeRect.setRight(itemRect.right() - 20); + + // 未读消息数 + QPoint msgNumPoint(itemRect.right() - 50, itemRect.bottom() - 30); + QSize msgNumSize(30, 20); + QRectF msgNumRect = QRect(msgNumPoint, msgNumSize); + msgNumRect.setRight(itemRect.right() - 20); + // 画圆 + QPainterPath numPath; + numPath.setFillRule( Qt::WindingFill ); //设置填充方式 + numPath.addRoundedRect (msgNumRect, 10, 10); + painter->fillPath(numPath, QBrush(QColor(250, 55, 55))); + + //绘制文字 + QTextOption option; + QFont textFont = painter->font(); + + option.setAlignment(Qt::AlignLeft | Qt::AlignTop); + textFont.setPixelSize(16); + painter->setFont(textFont); + painter->drawText(nicknameRect, nickname, option); + + // 白色的字 + painter->setPen(QPen(Qt::white)); + option.setAlignment(Qt::AlignCenter); + + textFont.setPixelSize(22); + painter->setFont(textFont); + painter->drawText(avatarRect, avatar, option); + + textFont.setPixelSize(12); + painter->setFont(textFont); + painter->drawText(msgNumRect, msgNum, option); + + // 灰色的字 + painter->setPen(QPen(QColor("#8C8C8C"))); + + option.setAlignment(Qt::AlignLeft | Qt::AlignTop); + textFont.setPixelSize(14); + painter->setFont(textFont); + painter->drawText(contentRect, msgContent, option); + + option.setAlignment(Qt::AlignRight | Qt::AlignTop); + painter->setFont(QFont(painter->fontInfo().family(), 12)); + painter->drawText(timeRect, msgTime, option); + + // QObject::setProperty("isWindowButton", 0x1); + // QObject::setProperty("useIconHighlightEffect", 0x2); + // setFlat(true); + painter->restore(); + } +} + +// bool FriendItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) +// { + +// } \ No newline at end of file diff --git a/src/view/friendlist/friendItemDelegate.h b/src/view/friendlist/friendItemDelegate.h new file mode 100644 index 0000000..86e1ff0 --- /dev/null +++ b/src/view/friendlist/friendItemDelegate.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef FRIENDITEMDELEGATE_H +#define FRIENDITEMDELEGATE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../model/friendlistmodel.h" + +class FriendItemDelegate : public QAbstractItemDelegate +{ + Q_OBJECT +public: + FriendItemDelegate(); + ~FriendItemDelegate(); + + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + // bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index); + +}; + + + + + +#endif // FRIENDITEMDELEGATE_H \ No newline at end of file diff --git a/src/view/friendlist/friendlist.cpp b/src/view/friendlist/friendlist.cpp new file mode 100644 index 0000000..ad2af78 --- /dev/null +++ b/src/view/friendlist/friendlist.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "friendlist.h" + + +FriendListView::FriendListView(QListView *parent) : + QListView(parent) +{ + QStringListModel *strListModel = new QStringListModel(this); + QStringList *strList = new QStringList(); + + strList->append("aaaaaaaaaaa"); + strList->append("bbbbbbbbbbb"); + strList->append("ccccccccccc"); + strList->insert(6, "66666666"); + + qDebug() << strList; + + strListModel->setStringList(*strList); + + FriendListModel *friendListModel = new FriendListModel(); + + for (int i = 0; i < 10; i++) { + friendListModel->addFriend(); + } + + FriendItemDelegate *myItemDelegate = new FriendItemDelegate(); + this->setItemDelegate(myItemDelegate); + + // this->setModel(strListModel); + this->setModel(friendListModel); + this->setSpacing(0); + this->setDragEnabled(false); + this->setFrameShape(QListView::NoFrame); + this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + this->verticalScrollBar()->setProperty("drawScrollBarGroove", false); + + // QThread::sleep(5); + + friendListModel->updateFriend(); + + delete strList; +} + +FriendListView::~FriendListView() +{ + +} \ No newline at end of file diff --git a/src/view/friendlist/friendlist.h b/src/view/friendlist/friendlist.h new file mode 100644 index 0000000..e3dadfa --- /dev/null +++ b/src/view/friendlist/friendlist.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef FRIENDLIST_H +#define FRIENDLIST_H + +#include +#include +#include +#include +#include +#include + +// #include "../../model/friendlistmodel.h" +#include "friendItemDelegate.h" + +typedef struct { + QString iconPath; + QString singer; + QString songsNb; +} MuItemData; + +Q_DECLARE_METATYPE(MuItemData) + +class FriendListView : public QListView +{ + +public: + FriendListView(QListView *parent = nullptr); + ~FriendListView(); + +private: + /* data */ +}; + + + + +#endif // FRIENDLIST_H \ No newline at end of file diff --git a/src/view/kyview.cpp b/src/view/kyview.cpp new file mode 100644 index 0000000..b3e9a95 --- /dev/null +++ b/src/view/kyview.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "kyview.h" + +// 生成静态实例 +KyView *KyView::getInstance() +{ + static KyView *instance = nullptr; + if (nullptr == instance) { + instance = new KyView(); + } + return instance; +} + +KyView::KyView(QWidget *parent) + : QWidget(parent) +{ + + // 初始化组件 + setWidgetUi(); + + // 设置组件样式 + setWidgetStyle(); +} + +KyView::~KyView() +{ +} + +// 最小化状态下拉起主界面 +void KyView::pullUpWindow() +{ + this->showNormal(); + this->raise(); + this->activateWindow(); +} + +// 初始化组件 +void KyView::setWidgetUi() +{ + this->setFixedSize(WINDOWW, WINDOWH); + + // mainWid = new QWidget(this); + + m_mainLayout = new QVBoxLayout(this); + + // 标题栏 + m_titleBar = new TitleBar(this); + m_titleBar->setFixedHeight(GlobalSizeData::TITLEBAR_HEIGHT); + + // 本机信息 + m_localInfo = new LocalInfo(this); + m_localInfo->setText("bb-本机","123.123.132.123"); + + // 好友列表 + m_friendListView = new FriendListView(); + + // 将组件添加到布局中 + m_mainLayout->addWidget(m_titleBar, Qt::AlignTop); + m_mainLayout->addWidget(m_localInfo, Qt::AlignTop); + m_mainLayout->addWidget(m_friendListView, Qt::AlignTop); + + m_mainLayout->setMargin(0); + m_mainLayout->setSpacing(0); + +} + +// 设置组件样式 +void KyView::setWidgetStyle() +{ + this->setAutoFillBackground(true); + this->setBackgroundRole(QPalette::Base); + + // 毛玻璃效果 + // this->setProperty("useSystemStyleBur", true); + // this->setAttribute(Qt::WA_TranslucentBackground, true); +} diff --git a/src/view/kyview.h b/src/view/kyview.h new file mode 100644 index 0000000..bb83171 --- /dev/null +++ b/src/view/kyview.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KYVIEW_H +#define KYVIEW_H + +#define WINDOWW 350 //窗口宽度 +#define WINDOWH 686 //窗口高度 +#define TITLEH 40 //标题栏高度 +#define LOCALINFOH 140 //本机信息高度 +#define FRIENDSLISTH 506 //好友列表高度 + +#include +#include + +#include "titlebar/titlebar.h" +#include "localinfo/localinfo.h" +#include "common/globalsizedata.h" +#include "friendlist/friendlist.h" + +class KyView : public QWidget +{ + Q_OBJECT + +public: + explicit KyView(QWidget *parent = nullptr); + ~KyView(); + + // 生成静态实例 + static KyView *getInstance(); + + // 初始化组件 + void setWidgetUi(); + + // 设置组件样式 + void setWidgetStyle(); + + // 最小化状态下拉起主界面 + void pullUpWindow(); + +private: + // 整体界面窗体 + QWidget *m_mainWid; + + // 标题栏 + TitleBar *m_titleBar; + + // 本机信息 + LocalInfo *m_localInfo; + + // 好友列表 + FriendListView *m_friendListView; + + // 整体界面布局 + QVBoxLayout *m_mainLayout; +}; + + + + +#endif // KYVIEW_H diff --git a/src/view/localinfo/localinfo.cpp b/src/view/localinfo/localinfo.cpp new file mode 100644 index 0000000..8e2f25b --- /dev/null +++ b/src/view/localinfo/localinfo.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "localinfo.h" +#include +#include + +LocalInfo::LocalInfo(QWidget *parent) + : QWidget(parent) +{ + // 初始化组件 + setWidgetUi(); + + // 设置组件样式 + setWidgetStyle(); +} + +LocalInfo::~LocalInfo() +{ +} + +// 初始化组件 +void LocalInfo::setWidgetUi() +{ + this->setFixedHeight(GlobalSizeData::LOCALINFO_HEIGHT); + + // 初始化组件及布局 + u_LabelIcon = new QLabel(this); + u_LabelName = new QLabel(this); + u_LabelIp = new QLabel(this); + u_ButtonUpdate = new QPushButton(this); + u_ButtonFile = new QPushButton(this); + + s_LabelIcon = new QLabel(this); + s_EditSearch=new QLineEdit(this); + + // 设置空间大小 + u_LabelIcon->setFixedSize(60,60); + u_ButtonUpdate->setFixedSize(20,20); + u_ButtonFile->setFixedSize(20,20); + s_EditSearch->setFixedSize(334, 36); + w = s_EditSearch->width(); + h = s_EditSearch->height(); + s_LabelIcon->setFixedSize(w/2-5,h); + + QMargins margins = s_EditSearch->textMargins(); + s_EditSearch->setTextMargins(margins.left(), margins.top(), s_LabelIcon->width(), margins.bottom()); + s_EditSearch->setPlaceholderText(tr("搜索"));//提示文字 + s_EditSearch->setMaxLength(30);//字数限制 + s_EditSearch->setTextMargins(s_LabelIcon->width(), 1, 1 , 1);// 设置输入框中文件输入区,不让输入的文字在被隐藏在按钮下 + + + m_localInfoLayout = new QVBoxLayout(this); + m_nameLayout = new QHBoxLayout(); + m_ipLayout = new QVBoxLayout(); + m_avatarLayout = new QHBoxLayout(); + m_searchLayout = new QHBoxLayout(); + // 对组件进行布局 + m_nameLayout->addWidget(u_LabelName, Qt::AlignBottom); + m_nameLayout->addWidget(u_ButtonUpdate, Qt::AlignBottom | Qt::AlignLeft); + m_nameLayout->addStretch(); + m_nameLayout->addWidget(u_ButtonFile, Qt::AlignBottom | Qt::AlignRight); + m_nameLayout->setMargin(0); + m_nameLayout->setSpacing(0); + + m_ipLayout->addLayout(m_nameLayout); + m_ipLayout->addWidget(u_LabelIp, Qt::AlignTop); + m_ipLayout->setMargin(0); + m_ipLayout->setSpacing(0); + + m_avatarLayout->addWidget(u_LabelIcon); + m_avatarLayout->addLayout(m_ipLayout); +// m_avatarLayout->setMargin(0); +// m_avatarLayout->setSpacing(0); + + m_localInfoLayout->addLayout(m_avatarLayout); + m_localInfoLayout->addWidget(s_EditSearch); + + m_searchLayout->addWidget(s_LabelIcon); + m_searchLayout->addStretch(); + m_searchLayout->setSpacing(0);/*各部件的相邻距离*/ + m_searchLayout->setContentsMargins(0, 0, 0, 0); + s_EditSearch->setLayout(m_searchLayout); + + this->installEventFilter(this);//安装过滤器 + u_ButtonUpdate->installEventFilter(this); + u_ButtonFile->installEventFilter(this); + s_EditSearch->installEventFilter(this); + + + // 设置对象名 + u_LabelIcon->setObjectName("usericon"); + u_LabelIp->setObjectName("userip"); + u_LabelName->setObjectName("username"); + u_ButtonUpdate->setObjectName("updatename"); + u_ButtonFile->setObjectName("uploadfile"); + + // 设置信号和槽函数 + connect(u_ButtonUpdate, SIGNAL(clicked(bool)), this, SLOT(onClicked())); + connect(u_ButtonFile, SIGNAL(clicked(bool)), this, SLOT(onClicked())); +} + +// 设置组件样式 +void LocalInfo::setWidgetStyle() +{ + this->setAutoFillBackground(true); + this->setBackgroundRole(QPalette::Base); + + // 设置图片 + //u_LabelName->setText("王晓晓-本机"); +// u_LabelName->setStyleSheet("color:#262626;font:16px;"); + QFont fontName; + fontName.setPixelSize(16); + u_LabelName->setFont(fontName); + u_LabelName->setAlignment(Qt::AlignBottom);//文字向下对齐 + u_LabelName->setMargin(0); + u_LabelName->setFixedSize(GlobalSizeData::USER_NAME_LAB_SIZE); + + //u_LabelIp->setText("123.123.123.123"); + u_LabelIp->setStyleSheet("color:#8c8c8c;font:14px;"); + u_LabelIp->setFixedSize(GlobalSizeData::USER_IP_LAB_SIZE); + + //u_LabelIcon->setText("王"); + u_LabelIcon->setAlignment(Qt::AlignCenter); + u_LabelIcon->setStyleSheet("background-color: #6495ED;border-radius:30px;padding:2px 4px;border-style: outset;color:white;font:36px;"); + u_LabelIcon->setFixedSize(GlobalSizeData::AVATAR_LAB_SIZE); + + u_ButtonUpdate->setIcon(QIcon::fromTheme("document-edit-symbolic"));/*修改名字*/ + u_ButtonUpdate->setIconSize(GlobalSizeData::OPEN_FOLDER_BTN_ICON); + u_ButtonUpdate->setFixedSize(GlobalSizeData::OPEN_FOLDER_BTN_SIZE); + u_ButtonUpdate->setProperty("isWindowButton", 0x1); + u_ButtonUpdate->setProperty("useIconHighlightEffect", 0x2); + u_ButtonUpdate->setFlat(true); + + u_ButtonFile->setIcon(QIcon::fromTheme("document-open-symbolic"));/*传输文件*/ + u_ButtonFile->setIconSize(GlobalSizeData::OPEN_FOLDER_BTN_ICON); + u_ButtonFile->setFixedSize(GlobalSizeData::OPEN_FOLDER_BTN_SIZE); + u_ButtonFile->setProperty("isWindowButton", 0x1); + u_ButtonFile->setProperty("useIconHighlightEffect", 0x2); + u_ButtonFile->setFlat(true); + + QFont font; + font.setPixelSize(14); + s_EditSearch->setFont(font); + + QIcon searchIcon = QIcon::fromTheme("preferences-system-search-symbolic"); + s_LabelIcon->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(20,20)))); + s_LabelIcon->setProperty("isWindowButton", 0x1); + s_LabelIcon->setProperty("useIconHighlightEffect", 0x2); + s_LabelIcon->setAlignment(Qt::AlignRight|Qt::AlignVCenter); +} + +bool LocalInfo::eventFilter(QObject *watch,QEvent *e) +{ + if(e->type() == QEvent::MouseButtonPress && watch != s_EditSearch) + { + this->setFocus(); + s_LabelIcon->setFixedSize(w/2-5,h); + s_LabelIcon->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + s_EditSearch->setAlignment(Qt::AlignLeft); + s_EditSearch->setTextMargins(s_LabelIcon->width(), 1, 1 , 1);//没有取消按钮的时候 + qDebug()<<"MouseButtonPress不是lineedit"; + } + if(e->type() == QEvent::MouseButtonPress && watch == s_EditSearch) + { + s_LabelIcon->setFixedSize(30, 30); + s_EditSearch->setAlignment(Qt::AlignLeft); + s_EditSearch->setTextMargins(s_LabelIcon->width(), 1, 1 , 1);//没有取消按钮的时候 + s_EditSearch->setFocus(); + s_EditSearch->setPlaceholderText("搜索");//提示文字 + qDebug()<<"MouseButtonPress是lineedit"; + } +} + +void LocalInfo::onClicked() +{ + QPushButton *pButton = qobject_cast(sender()); + QWidget *pWindow = this->window(); + if (pWindow->isTopLevel()) + { + if (pButton == u_ButtonUpdate) + { + qDebug()<<"~~~~~~~~~~~~修改名字~~~~~~~~~~~~"; + } + else if (pButton == u_ButtonFile) + { + qDebug()<<"~~~~~~~~~~~~文件夹~~~~~~~~~~~~"; + } + } +} + + +void LocalInfo::setText(QString name,QString IP) +{ + if(QString(name.at(0))>='a'&&QString(name.at(0))<='z'){ + + u_LabelIcon->setText(QString(name.at(0)).toUpper()); + u_LabelIcon->setStyleSheet("background-color: #6495ED;border-radius:30px;padding:2px 4px;border-style: outset;color:white;font:28px;"); + u_LabelIcon->setAlignment(Qt::AlignCenter); + + } + else{ + u_LabelIcon->setText(QString(name.at(0))); + u_LabelIcon->setStyleSheet("background-color: #6495ED;border-radius:30px;padding:2px 4px;border-style: outset;color:white;font:28px;"); + u_LabelIcon->setAlignment(Qt::AlignCenter); + } + u_LabelName->setText(name); + u_LabelIp->setText(IP); + +} diff --git a/src/view/localinfo/localinfo.h b/src/view/localinfo/localinfo.h new file mode 100644 index 0000000..1aa3d17 --- /dev/null +++ b/src/view/localinfo/localinfo.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LOCALINFO_H +#define LOCALINFO_H + +#include +#include +#include +#include +#include +#include + +#include "../common/globalsizedata.h" + +class LocalInfo : public QWidget +{ + Q_OBJECT +public: + explicit LocalInfo(QWidget *parent = nullptr); + ~LocalInfo(); + + // 初始化组件 + void setWidgetUi(); + + // 设置组件样式 + void setWidgetStyle(); + int w; + int h; + + QLabel *u_LabelIcon;//头像 + QLabel *s_LabelIcon;//搜索图标 + QLabel *u_LabelName;/*名字*/ + QLabel *u_LabelIp;/*IP*/ + QPushButton *u_ButtonUpdate;/*修改本机昵称按钮*/ + QPushButton *u_ButtonFile;/*打开文件保存目录按钮*/ + + void setText(QString name,QString IP); + + QLineEdit *s_EditSearch; + +private: + QVBoxLayout *m_localInfoLayout; // 本机信息总体布局 + QHBoxLayout *m_nameLayout; // 本机昵称布局 + QVBoxLayout *m_ipLayout; // 本机IP布局 + QHBoxLayout *m_avatarLayout; // 本机头像布局 + QHBoxLayout *m_searchLayout; // 搜索图像布局文本框 + +private slots: + // 进行置顶、最小化、关闭操作 + void onClicked(); + bool eventFilter(QObject *watch,QEvent *e); +}; + + + + +#endif // LOCALINFO_H diff --git a/src/view/titlebar/menumodule.cpp b/src/view/titlebar/menumodule.cpp new file mode 100644 index 0000000..4283cc3 --- /dev/null +++ b/src/view/titlebar/menumodule.cpp @@ -0,0 +1,423 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "menumodule.h" +#include "../common/xatom-helper.h" + +menuModule::menuModule(QWidget *parent = nullptr) : QWidget(parent) +{ + init(); +} + +void menuModule::init() +{ + initAction(); + setStyle(); +} + +void menuModule::initAction() +{ + // aboutWindow = new QWidget(); + titleText = new QLabel(); + bodyAppName = new QLabel(); + bodyAppVersion = new QLabel(); + bodySupport = new QLabel(); + + iconSize = QSize(30,30); + menuButton = new QToolButton(this); + menuButton->setToolTip(tr("Menu")); + menuButton->setProperty("isWindowButton", 0x1); + menuButton->setProperty("useIconHighlightEffect", 0x2); + menuButton->setPopupMode(QToolButton::InstantPopup); + menuButton->setFixedSize(30,30); + menuButton->setIconSize(QSize(16, 16)); + menuButton->setAutoRaise(true); + menuButton->setIcon(QIcon::fromTheme("open-menu-symbolic")); + + m_menu = new QMenu(); + QList actions ; + +// QAction *actionStandard = new QAction(m_menu); +// actionStandard->setText(tr("Standard")); +// QAction *actionScientific = new QAction(m_menu); +// actionScientific->setText(tr("Scientific")); +// QAction *actionExchangeRate = new QAction(m_menu); +// actionExchangeRate->setText(tr("Exchange Rate")); + +// QAction *separator = new QAction(m_menu); +// separator->setSeparator(true); + QAction *actionSetUp = new QAction(m_menu); + actionSetUp->setText(tr("设置")); + QAction *actionTheme = new QAction(m_menu); + actionTheme->setText(tr("主题")); + QAction *actionHelp = new QAction(m_menu); + actionHelp->setText(tr("帮助")); + QAction *actionAbout = new QAction(m_menu); + actionAbout->setText(tr("关于")); +// QAction *actionQuit = new QAction(m_menu); +// actionQuit->setText(tr("Quit")); + actions +// << actionStandard +// << actionScientific +// << actionExchangeRate +// << separator + << actionSetUp +// << actionTheme// + << actionHelp + << actionAbout; +// << actionQuit; + + m_menu->addActions(actions); + +// 互斥按钮组 + QMenu *themeMenu = new QMenu; + QActionGroup *themeMenuGroup = new QActionGroup(this); + QAction *autoTheme = new QAction(tr("跟随主题"),this); + themeMenuGroup->addAction(autoTheme); + themeMenu->addAction(autoTheme); + autoTheme->setCheckable(true); + QAction *lightTheme = new QAction(tr("浅色主题"),this); + themeMenuGroup->addAction(lightTheme); + themeMenu->addAction(lightTheme); + lightTheme->setCheckable(true); + QAction *darkTheme = new QAction(tr("深色主题"),this); + + themeMenuGroup->addAction(darkTheme); + themeMenu->addAction(darkTheme); + darkTheme->setCheckable(true); + QList themeActions; + themeActions<setChecked(true); + actionTheme->setMenu(themeMenu); + menuButton->setMenu(m_menu); + connect(m_menu,&QMenu::triggered,this,&menuModule::triggerMenu); + initGsetting(); + setThemeFromLocalThemeSetting(themeActions); + themeUpdate(); + connect(themeMenu,&QMenu::triggered,this,&menuModule::triggerThemeMenu); +} + +void menuModule::setThemeFromLocalThemeSetting(QList themeActions) +{ + m_pGsettingThemeStatus = new QGSettings(confPath.toLocal8Bit()); + QString appConf = m_pGsettingThemeStatus->get("thememode").toString(); + if("lightonly" == appConf){ + themeStatus = themeLightOnly; + themeActions[1]->setChecked(true); //程序gsetting中为浅色only的时候就给浅色按钮设置checked + }else if("darkonly" == appConf){ + themeStatus = themeBlackOnly; + themeActions[2]->setChecked(true); + }else{ + themeStatus = themeAuto; + themeActions[0]->setChecked(true); + } +} + +void menuModule::themeUpdate(){ + if(themeStatus == themeLightOnly) + { + setThemeLight(); + } + else if(themeStatus == themeBlackOnly){ + setThemeDark(); + } + else{ + setStyleByThemeGsetting(); + } +} + +void menuModule::setStyleByThemeGsetting(){ + QString nowThemeStyle = m_pGsettingThemeData->get("styleName").toString(); + if("ukui-dark" == nowThemeStyle || "ukui-black" == nowThemeStyle) { + setThemeDark(); + } + else { + setThemeLight(); + } +} + +void menuModule::triggerMenu(QAction *act) +{ + QString str = act->text(); +// if(tr("Quit") == str){ +// emit menuModuleClose(); +// } +// else if(tr("About") == str){ +// aboutAction(); +// } +// else if(tr("Help") == str){ +// helpAction(); +// } +// else if(tr("Standard") == str){ +// emit menuModuleChanged(QString("standard")); +// } +// else if(tr("Scientific") == str){ +// emit menuModuleChanged(QString("scientific")); +// } +// else if(tr("Exchange Rate") == str){ +// emit menuModuleChanged(QString("exchange rate")); +// } + if(tr("关于") == str){ + aboutAction(); + } + else if(tr("帮助") == str){ + helpAction(); + } + else if(tr("主题") == str){ + //emit menuModuleSetThemeStyle(QString("主题")); + } + else if(tr("设置") == str){ + + } +} + +void menuModule::triggerThemeMenu(QAction *act) +{ + if(!m_pGsettingThemeStatus) + { + m_pGsettingThemeStatus = new QGSettings(confPath.toLocal8Bit()); //m_pGsettingThemeStatus指针重复使用避免占用栈空间 + } + QString str = act->text(); + if("Light" == str){ + themeStatus = themeLightOnly; + disconnect(m_pGsettingThemeData,&QGSettings::changed,this,&menuModule::dealSystemGsettingChange); + m_pGsettingThemeStatus->set("thememode","lightonly"); +// disconnect() + setThemeLight(); + }else if("Dark" == str){ + themeStatus = themeBlackOnly; + disconnect(m_pGsettingThemeData,&QGSettings::changed,this,&menuModule::dealSystemGsettingChange); + m_pGsettingThemeStatus->set("thememode","darkonly"); + setThemeDark(); + }else{ + themeStatus = themeAuto; + m_pGsettingThemeStatus->set("thememode","auto"); + initGsetting(); +// updateTheme(); + themeUpdate(); + } +} + +void menuModule::aboutAction() +{ +// 关于点击事件处理 + // if (aboutWindow != nullptr) { + // aboutWindow->hide(); + + // QTime dieTime = QTime::currentTime().addMSecs(50); + // while( QTime::currentTime() < dieTime ) + // QCoreApplication::processEvents(QEventLoop::AllEvents, 100); + + + // aboutWindow->show(); + // // aboutWindow->activateWindow(); + // return ; + // } + initAbout(); +} + +void menuModule::helpAction() +{ + // 帮助点击事件处理 + if(!DaemonDbus::getInstance()->daemonIsNotRunning()){ + // qDebug() << "hahahahahaha" << appName; + DaemonDbus::getInstance()->showGuide(appName); + } +} + +#include +void menuModule::initAbout() +{ + aboutWindow = new QWidget(); + aboutWindow->setWindowFlag(Qt::Tool); + aboutWindow->setWindowIcon(QIcon::fromTheme("kylin-calculator")); + aboutWindow->setWindowModality(Qt::WindowModal); + aboutWindow->setWindowModality(Qt::ApplicationModal); + // aboutWindow->setModal(true); + // aboutWindow->setWindowFlags(Qt::FramelessWindowHint); + MotifWmHints hints; + // aboutWindow->setWindowFlags(Qt::WindowStaysOnTopHint); + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(aboutWindow->winId(), hints); + aboutWindow->setFixedSize(420,324); + aboutWindow->setMinimumHeight(324); + QVBoxLayout *mainlyt = new QVBoxLayout(); + QHBoxLayout *titleLyt = initTitleBar(); + QVBoxLayout *bodylyt = initBody(); + mainlyt->setContentsMargins(0,0,0,0); + mainlyt->setSpacing(0); + mainlyt->addLayout(titleLyt); + mainlyt->addLayout(bodylyt); + mainlyt->addStretch(); + aboutWindow->setLayout(mainlyt); + // 关于弹窗应用内居中 + QRect availableGeometry = this->parentWidget()->parentWidget()->parentWidget()->geometry(); + aboutWindow->move(availableGeometry.center() - aboutWindow->rect().center()); + // aboutWindow->setStyleSheet("background-color:rgba(255,255,255,1);"); + dealSystemGsettingChange("styleName"); + aboutWindow->show(); +} + +QHBoxLayout* menuModule::initTitleBar() +{ + QLabel* titleIcon = new QLabel(); + + titleIcon->setPixmap(QIcon::fromTheme("kylin-ipmsg").pixmap(titleIcon->size())); + titleIcon->setFixedSize(QSize(24,24)); + titleIcon->setScaledContents(true); + + QPushButton *titleBtnClose = new QPushButton; + titleBtnClose->setFixedSize(30,30); + titleBtnClose->setIcon(QIcon::fromTheme("window-close-symbolic")); + titleBtnClose->setProperty("isWindowButton",0x2); + titleBtnClose->setProperty("useIconHighlightEffect",0x8); + titleBtnClose->setFlat(true); + connect(titleBtnClose,&QPushButton::clicked,[=](){aboutWindow->close();}); + + titleText->setText(tr(appShowingName.toLocal8Bit())); + titleText->setStyleSheet("font-size:14px;"); + + QHBoxLayout *hlyt = new QHBoxLayout; + hlyt->setSpacing(0); + hlyt->setContentsMargins(4,4,4,4); + hlyt->addSpacing(4); + hlyt->addWidget(titleIcon); //居下显示 + hlyt->addSpacing(8); + hlyt->addWidget(titleText); + hlyt->addStretch(); + hlyt->addWidget(titleBtnClose); + + return hlyt; +} + +QVBoxLayout* menuModule::initBody() +{ + + QLabel* bodyIcon = new QLabel(); + bodyIcon->setFixedSize(96,96); + bodyIcon->setPixmap(QIcon::fromTheme("kylin-ipmsg").pixmap(bodyIcon->size())); + // bodyIcon->setStyleSheet("font-size:14px;"); + // bodyIcon->setScaledContents(true); + + bodyAppName->setFixedHeight(28); + bodyAppName->setText(tr(appShowingName.toLocal8Bit())); + bodyAppName->setStyleSheet("font-size:18px;"); + + bodyAppVersion->setFixedHeight(24); + bodyAppVersion->setText(tr("Version: ") + appVersion); + bodyAppVersion->setAlignment(Qt::AlignLeft); + bodyAppVersion->setStyleSheet("font-size:14px;"); + + connect(bodySupport,&QLabel::linkActivated,this,[=](const QString url){ + QDesktopServices::openUrl(QUrl(url)); + }); + bodySupport->setContextMenuPolicy(Qt::NoContextMenu); + bodySupport->setFixedHeight(24); + bodySupport->setStyleSheet("font-size:14px;"); + QVBoxLayout *vlyt = new QVBoxLayout; + vlyt->setMargin(0); + vlyt->setSpacing(0); + vlyt->addSpacing(20); + vlyt->addWidget(bodyIcon,0,Qt::AlignHCenter); + vlyt->addSpacing(16); + vlyt->addWidget(bodyAppName,0,Qt::AlignHCenter); + vlyt->addSpacing(12); + vlyt->addWidget(bodyAppVersion,0,Qt::AlignHCenter); + vlyt->addSpacing(12); + vlyt->addWidget(bodySupport,0,Qt::AlignHCenter); + vlyt->addStretch(); + return vlyt; +} + +void menuModule::setStyle() +{ + // menuButton->setObjectName("menuButton"); + // // qDebug() << "menuButton->styleSheet" << menuButton->styleSheet(); + // menuButton->setStyleSheet("QPushButton::menu-indicator{image:None;}"); +} + +void menuModule::initGsetting(){ + if(QGSettings::isSchemaInstalled(UKUI_THEME_GSETTING_PATH)){ + m_pGsettingThemeData = new QGSettings(UKUI_THEME_GSETTING_PATH); + connect(m_pGsettingThemeData,&QGSettings::changed,this,&menuModule::dealSystemGsettingChange); + } + +} + +void menuModule::keyPressEvent(QKeyEvent *event){ + if(event->key() == Qt::Key_F1){ + emit pullupHelp(); + }else{ + QWidget::keyPressEvent(event); + } +} + +void menuModule::dealSystemGsettingChange(const QString key) +{ + if(key == "styleName"){ + refreshThemeBySystemConf(); + } +} + +void menuModule::refreshThemeBySystemConf() +{ + QString themeNow = m_pGsettingThemeData->get("styleName").toString(); + if("ukui-dark" == themeNow || "ukui-black" == themeNow){ + setThemeDark(); + }else{ + setThemeLight(); + } +} + +void menuModule::setThemeDark() +{ + qDebug()<<"set theme dark"; + if(aboutWindow) + { + QPalette palette(this->palette()); + palette.setColor(QPalette::Background, QColor::fromRgb(13,13,14)); + aboutWindow->setPalette(palette); + // aboutWindow->setStyleSheet("background-color:rgba(13,13,14,1);"); + } + emit menuModuleSetThemeStyle("dark-theme"); + bodySupport->setText(tr("Service & Support: ") + + "" + "support@kylinos.cn"); + // menuButton->setProperty("setIconHighlightEffectDefaultColor", QColor(Qt::white)); +} + +void menuModule::setThemeLight() +{ +// qDebug()<<"set theme light"; + if(aboutWindow) + { + QPalette palette(this->palette()); + palette.setColor(QPalette::Background, QColor::fromRgb(255,255,255)); + aboutWindow->setPalette(palette); + // aboutWindow->setStyleSheet("background-color:rgba(255,255,255,1);"); + } + emit menuModuleSetThemeStyle("light-theme"); + bodySupport->setText(tr("Service & Support: ") + + "" + "support@kylinos.cn"); +} diff --git a/src/view/titlebar/menumodule.h b/src/view/titlebar/menumodule.h new file mode 100644 index 0000000..d95d8e1 --- /dev/null +++ b/src/view/titlebar/menumodule.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MENUMODULE_H +#define MENUMODULE_H + +#ifndef UKUI_THEME_GSETTING_PATH +#define UKUI_THEME_GSETTING_PATH "org.ukui.style" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/daemondbus.h" + +class menuModule : public QWidget +{ + Q_OBJECT +public: + explicit menuModule(QWidget *); + void themeUpdate(); + +signals: + void menuModuleClose(); + void menuModuleChanged(QString); + void pullupHelp(); + + void menuModuleSetThemeStyle(QString); +public: + QToolButton *menuButton = nullptr; + +public: +// 程序在实例化的时候需要传递的信息字段,打开debug开关后这些字段会被自动填充 + QString appName = "tools/kylin-calculator"; //格式kylin-usb-creator + QString appShowingName = tr("Calculator"); //格式kylin usb creator ,用来在前端展示 + QString appVersion = qApp->applicationVersion(); + QString appDesc = "kylin calculator"; + QString confPath = "org.kylin-calculator-data.settings"; + QWidget *aboutWindow = nullptr; +private: + QMenu *m_menu = nullptr; + QMenu *themeMenu = nullptr; + QSize iconSize; + QString appPath = "tools/kylin-calculator"; //拉起帮助菜单时使用appName字段 + + QGSettings *m_pGsettingThemeData = nullptr; + QGSettings *m_pGsettingThemeStatus = nullptr; + enum typeThemeStatus : int + { + themeAuto = 0, + themeBlackOnly = 1, + themeLightOnly = 2 + } themeStatus; + +public slots: + void dealSystemGsettingChange(const QString); +private: + void keyPressEvent(QKeyEvent *event); + void init(); + QHBoxLayout* initTitleBar(); //关于窗口标题栏初始化 + QVBoxLayout* initBody(); // 关于窗口body初始化 + void initGsetting(); + void initAction(); + void setStyle(); + void triggerMenu(QAction* act); //主菜单动作4 + void triggerThemeMenu(QAction* act); //主题动作 + void aboutAction(); + void initAbout(); //关于窗口初始化 + void helpAction(); + void setThemeFromLocalThemeSetting(QList); //获取本地主题配置 + void setStyleByThemeGsetting(); //通过外部主题配置设置主题 + void setThemeStyle(); + void setThemeLight(); + void setThemeDark(); +// void updateTheme(); //点击菜单中的主题设置后更新一次主题 + QLabel* titleText = nullptr; + QLabel* bodyAppName = nullptr; + QLabel* bodyAppVersion = nullptr; + QLabel* bodySupport = nullptr; + + void refreshThemeBySystemConf(); //通过系统配置更改主题 +}; + +#endif // MENUMODULE_H diff --git a/src/view/titlebar/titlebar.cpp b/src/view/titlebar/titlebar.cpp new file mode 100644 index 0000000..ae1224a --- /dev/null +++ b/src/view/titlebar/titlebar.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include +#include +#include +#include +#include "titlebar.h" +#include "../kyview.h" +#include "../common/xatom-helper.h" + +TitleBar::TitleBar(QWidget *parent) + : QWidget(parent) +{ + // 初始化组件 + setWidgetUi(); + + // 设置组件样式 + setWidgetStyle(); +} + +TitleBar::~TitleBar() +{ +} + +// 初始化组件 +void TitleBar::setWidgetUi() +{ + this->setFixedHeight(GlobalSizeData::TITLEBAR_HEIGHT); + // 窗体透明 +// this->setAttribute(Qt::WA_TranslucentBackground, true); +// this->setFixedHeight(38); /*固定高度*/ + + // 按钮初始化 + + m_pIconBtn = new QPushButton(this); + m_pFuncLabel = new QLabel(this); + m_pMinimizeButton = new QPushButton(this); + m_pCloseButton = new QPushButton(this); + + // 设置空间大小 + + menuBar = new menuModule(this); + + // 设置按钮布局 + pLayout = new QHBoxLayout(this); + pLayout->setContentsMargins(0, 0, 0, 0); + pLayout->setSpacing(1);/*各部件的相邻距离*/ + pLayout->addSpacing(2);/*插入间距*/ + pLayout->addWidget(m_pIconBtn); + pLayout->addSpacing(4); + pLayout->addWidget(m_pFuncLabel); + pLayout->addStretch();/*表示加了弹簧*/ + pLayout->addWidget(menuBar->menuButton); + pLayout->addSpacing(4); + pLayout->addWidget(m_pMinimizeButton); + pLayout->addSpacing(4); + pLayout->addWidget(m_pCloseButton); + + + this->setLayout(pLayout); + + // 设置信号和槽函数 + connect(m_pMinimizeButton, SIGNAL(clicked(bool)), this, SLOT(onClicked())); + connect(m_pCloseButton, SIGNAL(clicked(bool)), this, SLOT(onClicked())); +} + +// 设置组件样式 +void TitleBar::setWidgetStyle() +{ + this->setAutoFillBackground(true); + this->setBackgroundRole(QPalette::Base); + // 设置对象名 + m_pFuncLabel->setObjectName("whiteLabel"); + m_pMinimizeButton->setObjectName("minimizeButton"); + m_pCloseButton->setObjectName("closeButton"); + + // 设置悬浮提示 + m_pMinimizeButton->setToolTip(tr("Minimize")); + m_pCloseButton->setToolTip(tr("Close")); + + // 设置图片 + m_pFuncLabel->setText("麒麟传书");/*给label设置信息*/ + QFont font; + font.setPixelSize(14); + m_pFuncLabel->setFont(font); + + m_pIconBtn->setIconSize(QSize(21.11, 21.11));/*设置ico类型图片大小*/ + m_pIconBtn->setIcon(QIcon::fromTheme("kylin-ipmsg"));/*使用fromTheme函数调用库中的图片*/ + + m_pMinimizeButton->setIcon(QIcon::fromTheme("window-minimize-symbolic")); + m_pMinimizeButton->setIconSize(QSize(16, 16)); + m_pMinimizeButton->setProperty("isWindowButton", 0x1); + m_pMinimizeButton->setProperty("useIconHighlightEffect", 0x2); + m_pMinimizeButton->setFlat(true); + + m_pCloseButton->setIcon(QIcon::fromTheme("window-close-symbolic")); + m_pCloseButton->setIconSize (QSize(16, 16)); + m_pCloseButton->setProperty("isWindowButton", 0x2); + m_pCloseButton->setProperty("useIconHighlightEffect", 0x8); + m_pCloseButton->setFlat(true); + + // 设置按钮样式 + QString btnStyle = "QPushButton{border:0px;border-radius:4px;background:transparent;}" + "QPushButton:Hover{border:0px;border-radius:4px;background:transparent;background-color:rgba(0,0,0,0.1);}" + "QPushButton:Pressed{border:0px;border-radius:4px;background:transparent;background-color:rgba(0,0,0,0.15);}"; + m_pIconBtn->setStyleSheet(btnStyle); + +// if (WidgetStyle::themeColor == 0) { +// QString btnStyle = "QPushButton{border:0px;border-radius:4px;background:transparent;}" +// "QPushButton:Hover{border:0px;border-radius:4px;background:transparent;background-color:rgba(0,0,0,0.1);}" +// "QPushButton:Pressed{border:0px;border-radius:4px;background:transparent;background-color:rgba(0,0,0,0.15);}"; +// m_pIconBtn->setStyleSheet(btnStyle); +// } +// else if (WidgetStyle::themeColor == 1) { +// QString btnStyle = "QPushButton{border:0px;border-radius:4px;background:transparent;}" +// "QPushButton:Hover{border:0px;border-radius:4px;background:transparent;background-color:rgba(0,0,0,0.1);}" +// "QPushButton:Pressed{border:0px;border-radius:4px;background:transparent;background-color:rgba(0,0,0,0.15);}"; +// m_pIconBtn->setStyleSheet(btnStyle); + +// } + +} + +void TitleBar::onClicked() +{ + QPushButton *pButton = qobject_cast(sender()); + QWidget *pWindow = this->window(); + if (pWindow->isTopLevel()) + { + if (pButton == m_pMinimizeButton) + { + pWindow->showMinimized(); + m_pMinimizeButton->update(); + m_pCloseButton->update(); + } + else if (pButton == m_pCloseButton) + { + pWindow->close(); + } + } +} diff --git a/src/view/titlebar/titlebar.h b/src/view/titlebar/titlebar.h new file mode 100644 index 0000000..92bcddb --- /dev/null +++ b/src/view/titlebar/titlebar.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TITLEBAR_H +#define TITLEBAR_H + +#include +#include +#include +#include + +#include "menumodule.h" +#include "../common/globalsizedata.h" + +class TitleBar : public QWidget +{ + Q_OBJECT +public: + explicit TitleBar(QWidget *parent = nullptr); + ~TitleBar(); + + // 初始化组件 + void setWidgetUi(); + + // 设置组件样式 + void setWidgetStyle(); + +private: + // 整体界面布局 + QHBoxLayout *pLayout; + + QPushButton *m_pIconBtn; // 应用图标 + QLabel *m_pFuncLabel; // 界面标识 + menuModule *menuBar; /*菜单按钮*/ + QPushButton *m_pMinimizeButton; /*最小化按钮*/ + QPushButton *m_pCloseButton; /*关闭按钮*/ + +protected: + +#ifdef __V10__ + // 进行鼠标界面的拖动 + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); + virtual void mouseReleaseEvent(QMouseEvent *event); +#endif + +private slots: + + // 进行置顶、最小化、关闭操作 + void onClicked(); +}; + + +#endif // TITLEBAR_H diff --git a/theme.cpp b/theme.cpp deleted file mode 100644 index dd9ea57..0000000 --- a/theme.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "theme.h" - -const QString Theme::DEFAULT_THEME_COLOR = "#3a6cbc"; - - -Theme::Theme(QObject *parent) : - QObject(parent), - mColor1("#000000"), mColor2(DEFAULT_THEME_COLOR), mColor3("#4cb328"), - mColor4("#555555"), mColor5("#888888"), mColor6("#ffffff"), - mColor7("#cccccc"), mColor8("#eeeeee"), mColor9("#ccffffff"){ -} - -// 设置主题 -/* -* Parameters: -* color: theme color -* Return : -*/ -void Theme::setThemeColor(QString color) -{ - QColor c; - c.setNamedColor(color); - c.setRed(qMin(c.red() + 40, 255)); - c.setGreen(qMin(c.green() + 40, 255)); - c.setBlue(qMin(c.blue() + 40, 255)); - - mColor2 = color; - mColor3 = c.name(); - emit color2Changed(); - emit color3Changed(); -} - -// 具体颜色操作 -/* -* Parameters: -* color: theme color -* Return : -*/ -float Theme::getHue(QString color) { - - QColor c; - c.setNamedColor(color); - QColor converted = c.toHsv(); - return converted.hsvHueF(); -} - -/* -* Summary: get saturation -* Parameters: -* color: color -* Return : color saturation -*/ -float Theme::getSaturation(QString color) { - - QColor c; - c.setNamedColor(color); - QColor converted = c.toHsv(); - return converted.hsvSaturationF(); -} - -/* -* Summary: get lightness -* Parameters: -* color: color -* Return : lightness value -*/ -float Theme::getLightness(QString color) { - - QColor c; - c.setNamedColor(color); - QColor converted = c.toHsv(); - return converted.valueF(); -} diff --git a/theme.h b/theme.h deleted file mode 100644 index 7a162b7..0000000 --- a/theme.h +++ /dev/null @@ -1,86 +0,0 @@ -/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users - * Copyright (C) 2011 Emanuele Colombo - * 2020 KylinSoft Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef THEME_H -#define THEME_H - -#include -#include -#include - - -class Theme : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QString color1 READ color1 NOTIFY color1Changed) - Q_PROPERTY(QString color2 READ color2 NOTIFY color2Changed) - Q_PROPERTY(QString color3 READ color3 NOTIFY color3Changed) - Q_PROPERTY(QString color4 READ color4 NOTIFY color4Changed) - Q_PROPERTY(QString color5 READ color5 NOTIFY color5Changed) - Q_PROPERTY(QString color6 READ color6 NOTIFY color6Changed) - Q_PROPERTY(QString color7 READ color7 NOTIFY color7Changed) - Q_PROPERTY(QString color8 READ color8 NOTIFY color8Changed) - Q_PROPERTY(QString color9 READ color9 NOTIFY color9Changed) - -public: - explicit Theme(QObject *parent = 0); - inline QString color1() { return mColor1; } - inline QString color2() { return mColor2; } - inline QString color3() { return mColor3; } - inline QString color4() { return mColor4; } - inline QString color5() { return mColor5; } - inline QString color6() { return mColor6; } - inline QString color7() { return mColor7; } - inline QString color8() { return mColor8; } - inline QString color9() { return mColor9; } - void setThemeColor(QString color); - - static const QString DEFAULT_THEME_COLOR; - QString mColor1; - QString mColor2; - QString mColor3; - QString mColor4; - QString mColor5; - QString mColor6; - QString mColor7; - QString mColor8; - QString mColor9; - -signals: - void color1Changed(); - void color2Changed(); - void color3Changed(); - void color4Changed(); - void color5Changed(); - void color6Changed(); - void color7Changed(); - void color8Changed(); - void color9Changed(); - -public slots: - float getHue(QString color); - float getSaturation(QString color); - float getLightness(QString color); - -private: - -}; - -#endif // THEME_H