├── images ├── logo.rc ├── logo.ico ├── klipper.png ├── bluefish.png ├── configure.png ├── language.png ├── alipay_code.jpg ├── screenshot.png ├── document-encrypt.png ├── application-vnd.wordperfect.png ├── ic_file_download_black_48dp.png ├── ic_file_upload_black_48dp.png ├── network-wireless-connected-100.png └── bluefish.svg ├── lafdupapplication.h ├── lafdup.qrc ├── README.md ├── lafdupapplication.cpp ├── models.h ├── discovery.h ├── peer_p.h ├── models.cpp ├── CMakeLists.txt ├── lafdup_window.h ├── main.cpp ├── peer.h ├── password.ui ├── peers.ui ├── lafdup_window_p.h ├── _clang-format ├── guide.ui ├── main.ui ├── discovery.cpp ├── translations └── lafdup_zh_CN.ts ├── configure.ui ├── LICENSE └── peer.cpp /images/logo.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "logo.ico" -------------------------------------------------------------------------------- /images/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/logo.ico -------------------------------------------------------------------------------- /images/klipper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/klipper.png -------------------------------------------------------------------------------- /images/bluefish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/bluefish.png -------------------------------------------------------------------------------- /images/configure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/configure.png -------------------------------------------------------------------------------- /images/language.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/language.png -------------------------------------------------------------------------------- /images/alipay_code.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/alipay_code.jpg -------------------------------------------------------------------------------- /images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/screenshot.png -------------------------------------------------------------------------------- /images/document-encrypt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/document-encrypt.png -------------------------------------------------------------------------------- /images/application-vnd.wordperfect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/application-vnd.wordperfect.png -------------------------------------------------------------------------------- /images/ic_file_download_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/ic_file_download_black_48dp.png -------------------------------------------------------------------------------- /images/ic_file_upload_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/ic_file_upload_black_48dp.png -------------------------------------------------------------------------------- /images/network-wireless-connected-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgoldfish/lafdup/HEAD/images/network-wireless-connected-100.png -------------------------------------------------------------------------------- /lafdupapplication.h: -------------------------------------------------------------------------------- 1 | #ifndef LAFDUPAPPLICATION_H 2 | #define LAFDUPAPPLICATION_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define lpp static_cast(QCoreApplication::instance()) 10 | class LafdupApplication : public QApplication 11 | { 12 | Q_OBJECT 13 | public: 14 | LafdupApplication(int &argc, char **argv); 15 | ~LafdupApplication(); 16 | void translationLanguage(); 17 | public: 18 | QString languageStr; 19 | private: 20 | QTranslator *translationPtr; 21 | }; 22 | 23 | #endif // LAFDUPAPPLICATION_H 24 | -------------------------------------------------------------------------------- /lafdup.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/alipay_code.jpg 4 | images/application-vnd.wordperfect.png 5 | images/document-encrypt.png 6 | images/network-wireless-connected-100.png 7 | images/klipper.png 8 | images/configure.png 9 | images/ic_file_upload_black_48dp.png 10 | images/ic_file_download_black_48dp.png 11 | translations/lafdup_zh_CN.qm 12 | images/language.png 13 | images/bluefish.png 14 | images/logo.ico 15 | images/logo.rc 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SyncClipboard 2 | ============= 3 | 4 | ![Screenshot Of SyncClipboard](https://raw.githubusercontent.com/hgoldfish/lafdup/master/images/screenshot.png) 5 | 6 | 7 | Introduction 8 | ------------ 9 | 10 | Synchronize clipboard between computers by network broadcast. Data is encrypted using aes256-cbf. 11 | 12 | 13 | Download 14 | -------- 15 | 16 | [Windows Version](https://qtng.org/lafdup.7z) 17 | 18 | [Android Version](https://play.google.com/store/apps/details?id=com.hgoldfish.lafdup) 19 | 20 | 21 | License 22 | ------- 23 | 24 | SyncClipboard is distributed under GPL 3.0 license. 25 | 26 | 27 | Building 28 | -------- 29 | 30 | Require Qt 5.x to build. 31 | 32 | Using cmake to build this project. 33 | 34 | $ git clone https://github.com/hgoldfish/lafdup.git 35 | $ cd lafdup 36 | $ git clone https://github.com/hgoldfish/lafrpc.git 37 | $ git clone https://github.com/hgoldfish/qtnetworkng.git 38 | $ mkdir build 39 | $ cd build 40 | $ cmake .. 41 | $ make -j4 42 | -------------------------------------------------------------------------------- /lafdupapplication.cpp: -------------------------------------------------------------------------------- 1 | #include "lafdupapplication.h" 2 | 3 | LafdupApplication::LafdupApplication(int &argc, char **argv) 4 | : QApplication(argc, argv) 5 | , translationPtr(nullptr) 6 | { 7 | } 8 | 9 | LafdupApplication::~LafdupApplication() 10 | { 11 | delete translationPtr; 12 | } 13 | 14 | void LafdupApplication::translationLanguage() 15 | { 16 | if (nullptr != translationPtr) { 17 | removeTranslator(translationPtr); 18 | delete translationPtr; 19 | translationPtr = nullptr; 20 | } 21 | QSettings settings; 22 | QString languageSetting = settings.value("language").toString(); 23 | translationPtr = new QTranslator; 24 | languageStr = languageSetting; 25 | if (languageSetting == "Chinese_CN") { 26 | if (translationPtr->load(QLocale(), QLatin1String("lafdup"), QLatin1String("_"), 27 | QLatin1String(":/translations"))) 28 | installTranslator(translationPtr); 29 | } else { 30 | if (translationPtr->load(QLocale(), QLatin1String("lafdup"), QLatin1String("_"), 31 | QLatin1String(":/translations"))) 32 | removeTranslator(translationPtr); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /models.h: -------------------------------------------------------------------------------- 1 | #ifndef LAFDUP_MODELS_H 2 | #define LAFDUP_MODELS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | const QString TextType = "text/plain"; 10 | const QString BinaryType = "application/octet-stream"; 11 | const QString ImageType = "image/png"; 12 | const QString CompType = "comp"; 13 | 14 | struct CopyPaste 15 | { 16 | public: 17 | enum Direction { Incoming, Outgoing }; 18 | public: 19 | CopyPaste(const Direction &direction, const QDateTime ×tamp, const QString &text); 20 | CopyPaste(); 21 | public: 22 | Direction direction; 23 | QDateTime timestamp; 24 | QString mimeType; 25 | QString text; 26 | QByteArray image; 27 | QStringList files; 28 | bool ignoreLimits; 29 | bool isTextHtml; 30 | public: 31 | bool isText() const { return mimeType == TextType; } 32 | bool isFile() const { return mimeType == BinaryType; } 33 | bool isImage() const { return mimeType == ImageType; } 34 | bool isComp() const { return mimeType == CompType; } 35 | public: 36 | QVariantMap saveState(); 37 | bool restoreState(const QVariantMap &state); 38 | static QString lafrpcKey() { return "lafdup.CopyPaste"; } 39 | }; 40 | Q_DECLARE_METATYPE(CopyPaste); 41 | Q_DECLARE_METATYPE(QSharedPointer); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /discovery.h: -------------------------------------------------------------------------------- 1 | #ifndef LAFDUP_DISCOVERY_H 2 | #define LAFDUP_DISCOVERY_H 3 | 4 | #include "lafrpc.h" 5 | 6 | class LafdupDiscovery; 7 | class LafdupKcpSocket : public qtng::KcpSocket 8 | { 9 | public: 10 | LafdupKcpSocket(LafdupDiscovery *parent); 11 | virtual bool filter(char *data, qint32 *len, qtng::HostAddress *addr, quint16 *port) override; 12 | private: 13 | LafdupDiscovery *parent; 14 | }; 15 | 16 | class LafdupPeer; 17 | class LafdupDiscovery 18 | { 19 | public: 20 | LafdupDiscovery(const QByteArray &uuid, quint16 port, LafdupPeer *parent); 21 | ~LafdupDiscovery(); 22 | public: 23 | bool start(); 24 | void stop(); 25 | void setExtraKnownPeers(const QSet> &extraKnownPeers); 26 | QSet> getExtraKnownPeers(); 27 | QStringList getAllBoundAddresses(); 28 | quint16 getPort(); 29 | QByteArray getUuid(); 30 | static quint16 getDefaultPort(); 31 | private: 32 | void serve(); 33 | void discovery(); 34 | void handleDiscoveryRequest(const QByteArray &packet, qtng::HostAddress addr, quint16 port); 35 | private: 36 | QSharedPointer kcpSocket; 37 | qtng::CoroutineGroup *operations; 38 | QHash> knownPeers; 39 | QSet> extraKnownPeers; 40 | QByteArray uuid; 41 | LafdupPeer *parent; 42 | quint16 port; 43 | friend class LafdupKcpSocket; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /peer_p.h: -------------------------------------------------------------------------------- 1 | #ifndef LAFDUP_PEER_PH 2 | #define LAFDUP_PEER_PH 3 | 4 | #include "peer.h" 5 | 6 | struct PasteHashKey 7 | { 8 | PasteHashKey(QString _name, QDateTime _time) 9 | { 10 | name = _name; 11 | time = _time; 12 | }; 13 | QString name; 14 | QDateTime time; 15 | }; 16 | 17 | class LafdupRemoteStub : public QObject 18 | { 19 | Q_OBJECT 20 | public: 21 | LafdupRemoteStub(LafdupPeer *parent); 22 | public slots: 23 | bool pasteText(const QDateTime ×tamp, const QString &text); 24 | bool pasteFiles(const QDateTime ×tamp, QSharedPointer rpcDir); 25 | bool pasteImage(const QDateTime ×tamp, QSharedPointer image); 26 | bool pasteCompText(const QDateTime ×tamp, const QString &text,const bool &isHasTextHtml); 27 | bool pasteCompImage(const QDateTime ×tamp, QSharedPointer image); 28 | bool pasteCompFiles(const QDateTime ×tamp, QSharedPointer rpcDir); 29 | bool pasteEnd(const QDateTime &time); 30 | bool ping(); 31 | QDateTime getCurrentTime(); 32 | private: 33 | LafdupPeer *parent; 34 | QHash pasteHash; 35 | }; 36 | 37 | inline bool operator==(const PasteHashKey &p1, const PasteHashKey &p2) 38 | { 39 | return (p1.name == p2.name) && (p1.time == p2.time); 40 | }; 41 | 42 | inline uint qHash(const PasteHashKey &key, uint seed) noexcept 43 | { 44 | uint hash = qHash(key.name, seed); 45 | hash ^= qHash(key.time, hash); 46 | return hash; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /models.cpp: -------------------------------------------------------------------------------- 1 | #include "models.h" 2 | 3 | CopyPaste::CopyPaste(const Direction &direction, const QDateTime ×tamp, const QString &text) 4 | : direction(direction) 5 | , timestamp(timestamp) 6 | , mimeType(TextType) 7 | , text(text) 8 | , isTextHtml(false) 9 | { 10 | } 11 | 12 | CopyPaste::CopyPaste() 13 | : direction(Incoming) 14 | { 15 | } 16 | 17 | QVariantMap CopyPaste::saveState() 18 | { 19 | QVariantMap state; 20 | // if (type == CopyPasteType::Incoming) { 21 | // state.insert("type", 1); 22 | // } else { 23 | // state.insert("type", 2); 24 | // } 25 | state.insert("timestamp", timestamp); 26 | state.insert("mime_type", mimeType); 27 | if (mimeType == TextType) { 28 | state.insert("text", text); 29 | } else if (mimeType == ImageType) { 30 | state.insert("image", image); 31 | } else if (mimeType == BinaryType) { 32 | state.insert("files", files); 33 | } else { 34 | } 35 | return state; 36 | } 37 | 38 | bool CopyPaste::restoreState(const QVariantMap &state) 39 | { 40 | // bool ok; 41 | // if (state.value("type").toInt(&ok) == 1) { 42 | // type = Incoming; 43 | // } else if (state.value("type").toInt(&ok) == 2) { 44 | // type = Outgoing; 45 | // } else { 46 | // return false; 47 | // } 48 | // if (!ok) { 49 | // return false; 50 | // } 51 | timestamp = state.value("timestamp").toDateTime(); 52 | mimeType = state.value("mime_type").toString(); 53 | text = state.value("text").toString(); 54 | image = state.value("image").toByteArray(); 55 | files = state.value("files").toStringList(); 56 | if (!timestamp.isValid() || mimeType.isEmpty()) { 57 | return false; 58 | } 59 | if (mimeType == TextType) { 60 | return !text.isEmpty(); 61 | } else if (mimeType == ImageType) { 62 | return !image.isEmpty(); 63 | } else if (mimeType == BinaryType) { 64 | return !files.isEmpty(); 65 | } else { 66 | return false; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR) 2 | 3 | if (POLICY CMP0071) 4 | cmake_policy(SET CMP0071 NEW) 5 | endif () 6 | 7 | project(lafdup) 8 | 9 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../lafrpc/cpp/lafrpc.h") 10 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../lafrpc/cpp/ lafrpc) 11 | elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../lafrpc/cpp/lafrpc.h") 12 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../lafrpc/cpp/ lafrpc) 13 | else() 14 | add_subdirectory(lafrpc/cpp lafrpc) 15 | endif() 16 | 17 | cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR) 18 | 19 | set(CMAKE_AUTOMOC ON) 20 | SET(CMAKE_AUTOUIC ON) 21 | set(CMAKE_AUTORCC ON) 22 | set(CMAKE_CXX_STANDARD 11) 23 | 24 | find_package(Qt5Core REQUIRED) 25 | find_package(Qt5Widgets REQUIRED) 26 | 27 | set(LAFDUP_SRC 28 | main.cpp 29 | lafdup_window.cpp 30 | lafdup_window.h 31 | lafdup_window_p.h 32 | lafdupapplication.h 33 | lafdupapplication.cpp 34 | lafdup.qrc 35 | images/logo.rc 36 | 37 | peer.h 38 | peer_p.h 39 | discovery.h 40 | models.h 41 | 42 | peer.cpp 43 | discovery.cpp 44 | models.cpp 45 | 46 | main.ui 47 | password.ui 48 | configure.ui 49 | guide.ui 50 | ) 51 | 52 | add_definitions(-DQT_NO_CAST_TO_ASCII) 53 | if (MSVC) 54 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") 55 | endif() 56 | 57 | add_executable(lafdup WIN32 ${LAFDUP_SRC}) 58 | target_link_libraries(lafdup Qt5::Widgets Qt5::Core lafrpc) 59 | 60 | #查找Qt翻译工具 61 | find_package(Qt5 REQUIRED COMPONENTS LinguistTools REQUIRED) 62 | 63 | # 初始化要使用的列表 64 | set(TS_FILES 65 | translations/lafdup_zh_CN.ts 66 | ) 67 | set(QM_FILES) 68 | 69 | # 设置翻译文件的生成路径,如果不指定就会生成在CMakeFiles的目录里 70 | set_source_files_properties(${TS_FILES} 71 | PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/translations 72 | ) 73 | # 创建翻译的最关键一步 74 | qt5_create_translation(QM_FILES ${TS_FILES} ${LAFDUP_SRC} OPTIONS -no-obsolete -no-ui-lines) 75 | 76 | # 添加更新翻译的目标 77 | add_custom_target(lupdate_task DEPENDS ${TS_FILES}) 78 | add_custom_target(lrelease_task DEPENDS ${QM_FILES}) 79 | 80 | 81 | -------------------------------------------------------------------------------- /lafdup_window.h: -------------------------------------------------------------------------------- 1 | #ifndef LAFDUP_WINDOW_H 2 | #define LAFDUP_WINDOW_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "peer.h" 9 | namespace Ui { 10 | class LafdupWindow; 11 | } 12 | class GuideDialog; 13 | class MessageTips; 14 | class CopyPasteModel; 15 | class LafdupWindow : public QWidget 16 | { 17 | Q_OBJECT 18 | public: 19 | LafdupWindow(); 20 | virtual ~LafdupWindow() override; 21 | protected: 22 | virtual void showEvent(QShowEvent *event) override; 23 | virtual void changeEvent(QEvent *event) override; 24 | virtual void closeEvent(QCloseEvent *event) override; 25 | virtual void dropEvent(QDropEvent *event) override; 26 | virtual void dragEnterEvent(QDragEnterEvent *event) override; 27 | bool event(QEvent *e) override; 28 | public slots: 29 | void sendContent(); 30 | void showAndGetFocus(); 31 | 32 | private slots: 33 | void updateClipboard(const CopyPaste ©Paste); 34 | void onPeerStateChanged(bool ok); 35 | void configure(); 36 | void setPassword(); 37 | void useOldContent(const QModelIndex ¤t); 38 | void showContextMenu(const QPoint &pos); 39 | void copyToRemote(); 40 | void setToClipboard(); 41 | void removeCopyPaste(); 42 | void clearAll(); 43 | void sendFiles(); 44 | void sendFeedBackTips(QString tips); 45 | void sendAction(); 46 | void saveTextToLocal(); 47 | void saveFilesToLocal(); 48 | void savaImageToLocal(); 49 | void setWindowTop(int state); 50 | public slots: 51 | void onClipboardChanged(); 52 | private: 53 | bool outgoing(const QString &text, bool ignoreLimits); 54 | bool outgoing(const QList urls, bool showError, bool ignoreLimits); 55 | bool isExcelDataCopied(const QMimeData *mimeData); 56 | bool copyFolder(const QString &fromDir, const QString &toDir); 57 | void updateMyIP(); 58 | void loadPassword(); 59 | void loadConfiguration(bool withPassword); 60 | private: 61 | Ui::LafdupWindow *ui; 62 | QSharedPointer peer; 63 | CopyPasteModel *copyPasteModel; 64 | QSystemTrayIcon *trayIcon; 65 | QMenu *trayMenu; 66 | bool started; 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "lafdup_window.h" 7 | #include "lafdupapplication.h" 8 | #include "qtnetworkng.h" 9 | #include "lafdup_window_p.h" 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | qSetMessagePattern("[%{time yyyyMMdd h:mm:ss.zzz}] - %{message}"); 15 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); 16 | QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); 17 | 18 | LafdupApplication app(argc, argv); 19 | app.setOrganizationDomain("lafdup.gigacores.com"); 20 | app.setOrganizationName("GigaCores"); 21 | app.setApplicationDisplayName("Sync Clipboard"); 22 | app.setApplicationName("SyncClipboard"); 23 | app.setApplicationVersion("1.0"); 24 | app.setWindowIcon(QIcon(":/images/bluefish.png")); 25 | app.setQuitOnLastWindowClosed(false); 26 | 27 | QCommandLineParser parser; 28 | parser.setApplicationDescription("Keep clipboard synchroized to other PCs."); 29 | parser.addHelpOption(); 30 | QCommandLineOption minimizedOption("m", "minimized after started."); 31 | parser.addOption(minimizedOption); 32 | parser.process(app); 33 | 34 | #ifdef Q_OS_WIN 35 | QFont f = app.font(); 36 | f.setFamily("微软雅黑"); 37 | app.setFont(f); 38 | app.setStyle(QStyleFactory::create("fusion")); 39 | #endif 40 | app.translationLanguage(); 41 | 42 | QSystemSemaphore sema("systemSemaphore", 1, QSystemSemaphore::Open); 43 | sema.acquire(); 44 | QSharedMemory mem("memory"); 45 | if (!mem.create(1)) { 46 | QMessageBox::information(nullptr, QObject::tr("tips"), 47 | QObject::tr("The program is running, please exit first if necessary")); 48 | sema.release(); 49 | return 0; 50 | } 51 | sema.release(); 52 | 53 | QSettings *settings = new QSettings; 54 | if (settings->value("password").toString().isEmpty()) { 55 | GuideDialog guide; 56 | guide.show(); 57 | int result = guide.exec(); 58 | if (result != QDialog::Accepted) { 59 | return 0; 60 | } 61 | } 62 | 63 | LafdupWindow w; 64 | if (settings->value("isMinimized").toBool()) { 65 | w.showMinimized(); 66 | } else { 67 | w.showAndGetFocus(); 68 | } 69 | delete settings; 70 | return qtng::startQtLoop(); 71 | } 72 | -------------------------------------------------------------------------------- /peer.h: -------------------------------------------------------------------------------- 1 | #ifndef LAFDUP_PEER_H 2 | #define LAFDUP_PEER_H 3 | 4 | #include 5 | #include "lafrpc.h" 6 | #include "models.h" 7 | 8 | class LafdupDiscovery; 9 | class LafdupRemoteStub; 10 | 11 | class LafdupPeer : public QObject 12 | { 13 | Q_OBJECT 14 | public: 15 | LafdupPeer(const QByteArray &uuid, quint16 port); 16 | virtual ~LafdupPeer() override; 17 | public: 18 | bool start(); 19 | void stop(); 20 | void outgoing(const CopyPaste ©Paste); 21 | void setPassword(QByteArray password); 22 | void setExtraKnownPeers(const QSet> &extraKnownPeers); 23 | void setCacheDir(const QString &cacheDir); 24 | void setDeleteFilesTime(int minutes); 25 | void setSendFilesSize(float mb); 26 | void setIgnorePassword(bool ignorePassword); 27 | QStringList getAllBoundAddresses(); 28 | quint16 getPort(); 29 | static quint16 getDefaultPort(); 30 | signals: 31 | void incoming(const CopyPaste ©Paste); 32 | void stateChanged(bool ok); 33 | void sendFeedBack(QString str); 34 | void sendAction(); 35 | protected: 36 | bool hasPeer(const qtng::HostAddress &remoteHost, quint16 port); 37 | bool hasPeer(const QString &peerName); 38 | void tryToConnectPeer(QString itsPeerName, qtng::HostAddress remoteHost, quint16 port); 39 | void tryToConnectPeer(QSharedPointer request); 40 | private: 41 | void handleKcpRequestSync(QSharedPointer request, qtng::DataChannelPole pole, 42 | const QString &itsPeerName); 43 | QSharedPointer handleRequestSync(QSharedPointer request, qtng::DataChannelPole pole, 44 | const QString &itsPeerName, const QString &itsAddress); 45 | void _outgoingSync(CopyPaste copyPaste); 46 | bool canSendContent(const CopyPaste ©Paste); 47 | 48 | bool findItem(const QDateTime ×tamp); 49 | bool findItem(const CopyPaste ¤tItem); 50 | void writeInformation(const QDir destDir); 51 | void cleanFiles(); 52 | void _cleanFiles(const QDir &dir, bool cleanAll); 53 | bool sendContentToPeer(QSharedPointer peer, const CopyPaste ©Paste, QString *errorString); 54 | private: 55 | QSharedPointer discovery; 56 | QSharedPointer stub; 57 | QSharedPointer cipher; 58 | QList items; 59 | QSet connectingPeers; 60 | QString cacheDir; 61 | int deleteFilesTime; 62 | float sendFilesSize; 63 | bool ignorePassword; 64 | bool cleaningFiles; 65 | qtng::CoroutineGroup *operations; 66 | friend LafdupRemoteStub; 67 | friend LafdupDiscovery; 68 | friend struct MarkCleaning; 69 | public: 70 | QSharedPointer rpc; 71 | }; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /password.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | PasswordDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 398 10 | 229 11 | 12 | 13 | 14 | Change Password 15 | 16 | 17 | 18 | 19 | 20 | 21 | 0 22 | 0 23 | 24 | 25 | 26 | Sync Clipboard uses AES/SHA256 to protect the data transmition between computers. All personal computers and mobile phones use the same password here. Note: this password is stored in the Windows registry in clear text. DO NOT use the same password of your critical data. 27 | 28 | 29 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 30 | 31 | 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | QLineEdit::PasswordEchoOnEdit 40 | 41 | 42 | Password for sending content 43 | 44 | 45 | 46 | 47 | 48 | 49 | Qt::Horizontal 50 | 51 | 52 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | buttonBox 62 | accepted() 63 | PasswordDialog 64 | accept() 65 | 66 | 67 | 248 68 | 254 69 | 70 | 71 | 157 72 | 274 73 | 74 | 75 | 76 | 77 | buttonBox 78 | rejected() 79 | PasswordDialog 80 | reject() 81 | 82 | 83 | 316 84 | 260 85 | 86 | 87 | 286 88 | 274 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /peers.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ManagePeersDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 554 10 | 378 11 | 12 | 13 | 14 | Manage the IP addresses of other Peers 15 | 16 | 17 | 18 | 19 | 20 | Sync Clipboard sends broadcast to your personal computers and mobile phones which connect to the same network as this computer. You might add the IP addresses of your other personal computers or mobile phones here, only if they connect to a different network. 21 | 22 | 23 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 24 | 25 | 26 | true 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 192.168.1.105 36 | 37 | 38 | 39 | 40 | 41 | 42 | &Add 43 | 44 | 45 | true 46 | 47 | 48 | 49 | 50 | 51 | 52 | &Remove Selected IP 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | QDialogButtonBox::Cancel|QDialogButtonBox::Save 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | buttonBox 74 | accepted() 75 | ManagePeersDialog 76 | accept() 77 | 78 | 79 | 263 80 | 364 81 | 82 | 83 | 263 84 | 193 85 | 86 | 87 | 88 | 89 | buttonBox 90 | rejected() 91 | ManagePeersDialog 92 | reject() 93 | 94 | 95 | 263 96 | 364 97 | 98 | 99 | 263 100 | 193 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /lafdup_window_p.h: -------------------------------------------------------------------------------- 1 | #ifndef LAFDUP_WINDOW_P_H 2 | #define LAFDUP_WINDOW_P_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "lafdup_window.h" 8 | 9 | namespace Ui { 10 | class PasswordDialog; 11 | class ConfigureDialog; 12 | class GuideDialog; 13 | } // namespace Ui 14 | 15 | class CopyPasteModel : public QAbstractListModel 16 | { 17 | Q_OBJECT 18 | public: 19 | CopyPasteModel(); 20 | public: 21 | int rowCount(const QModelIndex &parent) const override; 22 | QVariant data(const QModelIndex &index, int role) const override; 23 | public: 24 | // bool checkLastCopyPaste(CopyPaste::Direction direction, const QString &text) const; 25 | QModelIndex addCopyPaste(const CopyPaste ©Paste); 26 | CopyPaste copyPasteAt(const QModelIndex &index) const; 27 | bool removeCopyPaste(const QModelIndex &index); 28 | void clearAll(); 29 | private: 30 | QList copyPasteList; 31 | }; 32 | 33 | class PeerModel : public QAbstractListModel 34 | { 35 | public: 36 | void setPeers(const QStringList &peers); 37 | QStringList getPeers() const { return peers; } 38 | QModelIndex addPeer(const QString &peer); 39 | bool removePeer(const QModelIndex &index); 40 | public: 41 | virtual int rowCount(const QModelIndex &parent) const override; 42 | virtual QVariant data(const QModelIndex &index, int role) const override; 43 | private: 44 | QStringList peers; 45 | }; 46 | 47 | class PasswordDialog : public QDialog 48 | { 49 | Q_OBJECT 50 | public: 51 | PasswordDialog(QWidget *parent); 52 | virtual ~PasswordDialog() override; 53 | public: 54 | virtual void accept() override; 55 | private: 56 | Ui::PasswordDialog *ui; 57 | }; 58 | 59 | class ConfigureDialog : public QDialog 60 | { 61 | Q_OBJECT 62 | public: 63 | ConfigureDialog(QWidget *parent); 64 | virtual ~ConfigureDialog() override; 65 | public: 66 | virtual void accept() override; 67 | bool isPasswordChanged(); 68 | private slots: 69 | void onCacheDirectoryChanged(const QString &text); 70 | void selectCacheDirectory(); 71 | void onDeleteFilesChanged(bool checked); 72 | void onSendFilesChanged(bool checked); 73 | void onOnlySendSmallFileChanged(bool checked); 74 | void removeSelectedPeer(); 75 | void addPeer(); 76 | void onChangelanguage(); 77 | private: 78 | void loadSettings(); 79 | void appAutoRun(bool checked); 80 | private: 81 | Ui::ConfigureDialog *ui; 82 | PeerModel *peerModel; 83 | }; 84 | 85 | class MessageTips : public QWidget 86 | { 87 | Q_OBJECT 88 | public: 89 | MessageTips(const QString &str, QWidget *partent = nullptr); 90 | ~MessageTips(); 91 | void prepare(); 92 | void setCloseTimeSpeed(int closeTime = 100, double closeSpeed = 0.1); 93 | void setShowTime(int time); 94 | void backgroundColor(QColor color); 95 | static void showMessageTips(QString str, QWidget *parent = nullptr); 96 | protected: 97 | void paintEvent(QPaintEvent *event) override; 98 | private slots: 99 | void opacityTimer(); 100 | void timerDelayShutdown(); 101 | private: 102 | QString showStr; 103 | double opacity = 0.8; 104 | int textSize = 12; // 显示字体大小 105 | QColor textColor = QColor(255, 255, 255); // 字体颜色 106 | QColor bgColor = QColor(0, 191, 255); // 窗体的背景色 107 | QColor frameColor = QColor(211, 211, 211); // 边框颜色 108 | int frameSize = 1; // 边框粗细大小 109 | int showTime = 5000; // 显示时间 110 | int closeTime = 100; // 关闭需要时间 111 | double closeSpeed = 0.1; // 窗体消失的平滑度,大小0~1 112 | QTimer *mtimer = nullptr; 113 | }; 114 | 115 | class GuideDialog : public QDialog 116 | { 117 | Q_OBJECT 118 | public: 119 | GuideDialog(QWidget *parent = nullptr); 120 | ~GuideDialog(); 121 | virtual void accept() override; 122 | private: 123 | void setRecvFileDirectory(); 124 | private: 125 | Ui::GuideDialog *ui; 126 | }; 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /_clang-format: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 Olivier Goffart 2 | # 3 | # You may use this file under the terms of the 3-clause BSD license. 4 | # See the file LICENSE from this package for details. 5 | 6 | # This is the clang-format configuration style to be used by Qt, 7 | # based on the rules from https://wiki.qt.io/Qt_Coding_Style and 8 | # https://wiki.qt.io/Coding_Conventions 9 | 10 | --- 11 | # Webkit style was loosely based on the Qt style 12 | BasedOnStyle: WebKit 13 | 14 | Standard: c++11 15 | 16 | # Column width is limited to 100 in accordance with Qt Coding Style. 17 | # https://wiki.qt.io/Qt_Coding_Style 18 | # Note that this may be changed at some point in the future. 19 | #ColumnLimit: 100 20 | # How much weight do extra characters after the line length limit have. 21 | # PenaltyExcessCharacter: 4 22 | 23 | # Disable reflow of some specific comments 24 | # qdoc comments: indentation rules are different. 25 | # Translation comments and SPDX license identifiers are also excluded. 26 | CommentPragmas: "^!|^:|^ SPDX-License-Identifier:" 27 | 28 | # We want a space between the type and the star for pointer types. 29 | PointerBindsToType: false 30 | 31 | # We use template< without space. 32 | SpaceAfterTemplateKeyword: false 33 | 34 | # We want to break before the operators, but not before a '='. 35 | BreakBeforeBinaryOperators: NonAssignment 36 | 37 | # Braces are usually attached, but not after functions or class declarations. 38 | BreakBeforeBraces: Custom 39 | BraceWrapping: 40 | AfterClass: true 41 | AfterControlStatement: false 42 | AfterEnum: false 43 | AfterFunction: true 44 | AfterNamespace: false 45 | AfterObjCDeclaration: false 46 | AfterStruct: true 47 | AfterUnion: false 48 | BeforeCatch: false 49 | BeforeElse: false 50 | IndentBraces: false 51 | 52 | # When constructor initializers do not fit on one line, put them each on a new line. 53 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 54 | # Indent initializers by 4 spaces 55 | ConstructorInitializerIndentWidth: 4 56 | 57 | # Indent width for line continuations. 58 | ContinuationIndentWidth: 8 59 | 60 | # No indentation for namespaces. 61 | NamespaceIndentation: None 62 | 63 | # 旧版本不支持 64 | # Allow indentation for preprocessing directives (if/ifdef/endif). https://reviews.llvm.org/rL312125 65 | # IndentPPDirectives: AfterHash 66 | # We only indent with 2 spaces for preprocessor directives 67 | # PPIndentWidth: 2 68 | 69 | # Horizontally align arguments after an open bracket. 70 | # The coding style does not specify the following, but this is what gives 71 | # results closest to the existing code. 72 | AlignAfterOpenBracket: true 73 | AlwaysBreakTemplateDeclarations: true 74 | 75 | # Ideally we should also allow less short function in a single line, but 76 | # clang-format does not handle that. 77 | AllowShortFunctionsOnASingleLine: Inline 78 | 79 | # The coding style specifies some include order categories, but also tells to 80 | # separate categories with an empty line. It does not specify the order within 81 | # the categories. Since the SortInclude feature of clang-format does not 82 | # re-order includes separated by empty lines, the feature is not used. 83 | SortIncludes: false 84 | 85 | # macros for which the opening brace stays attached. 86 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ] 87 | 88 | # Add "// namespace " comments on closing brace for a namespace 89 | # Ignored for namespaces that qualify as a short namespace, 90 | # see 'ShortNamespaceLines' 91 | FixNamespaceComments: true 92 | 93 | # Definition of how short a short namespace is, default 1 94 | # 旧版本不支持 95 | # ShortNamespaceLines: 1 96 | 97 | # When escaping newlines in a macro attach the '\' as far left as possible, e.g. 98 | ##define a \ 99 | # something; \ 100 | # other; \ 101 | # thelastlineislong; 102 | AlignEscapedNewlines: Left 103 | 104 | # Avoids the addition of a space between an identifier and the 105 | # initializer list in list-initialization. 106 | SpaceBeforeCpp11BracedList: false 107 | 108 | 109 | 110 | # Goldfish 111 | # Standard: c++11 112 | BreakConstructorInitializers: BeforeComma 113 | BreakInheritanceList: BeforeComma 114 | BreakStringLiterals: true 115 | EmptyLineBeforeAccessModifier: Never 116 | #FixNamespaceComments: true 117 | IndentExternBlock: NoIndent 118 | ColumnLimit: 120 119 | UseTab: Never 120 | SpacesBeforeTrailingComments: 2 121 | # SpaceBeforeRangeBasedForLoopColon: false 122 | SpaceBeforeParens: ControlStatements 123 | # SpaceBeforeInheritanceColon: false 124 | # SpaceBeforeCpp11BracedList: true 125 | # SpaceBeforeCaseColon: false 126 | SpaceBeforeAssignmentOperators: true 127 | SpaceAroundPointerQualifiers: Both 128 | #SpaceAfterTemplateKeyword: false 129 | SpaceAfterLogicalNot: false 130 | SpaceAfterCStyleCast: true -------------------------------------------------------------------------------- /images/bluefish.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /guide.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | GuideDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 473 10 | 216 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | 4 21 | 22 | 23 | 24 | 25 | 26 | 50 27 | 0 28 | 29 | 30 | 31 | Password: 32 | 33 | 34 | 35 | 36 | 37 | 38 | Qt::Horizontal 39 | 40 | 41 | QSizePolicy::Maximum 42 | 43 | 44 | 45 | 10 46 | 20 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 200 56 | 0 57 | 58 | 59 | 60 | QLineEdit::PasswordEchoOnEdit 61 | 62 | 63 | Cannot be null 64 | 65 | 66 | 67 | 68 | 69 | 70 | Qt::Horizontal 71 | 72 | 73 | 74 | 40 75 | 20 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 16777215 89 | 40 90 | 91 | 92 | 93 | You need to set a password to ensure the security of data transmissionel 94 | Sending and receiving can only be achieved if the sender and receiver use the same password 95 | 96 | 97 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 98 | 99 | 100 | 101 | 102 | 103 | 104 | Qt::Horizontal 105 | 106 | 107 | 108 | 40 109 | 20 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 50 123 | 0 124 | 125 | 126 | 127 | Directory: 128 | 129 | 130 | 131 | 132 | 133 | 134 | Qt::Horizontal 135 | 136 | 137 | QSizePolicy::Maximum 138 | 139 | 140 | 141 | 10 142 | 20 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 200 152 | 0 153 | 154 | 155 | 156 | true 157 | 158 | 159 | 160 | 161 | 162 | 163 | Browse 164 | 165 | 166 | 167 | 168 | 169 | 170 | Qt::Horizontal 171 | 172 | 173 | 174 | 40 175 | 20 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 16777215 189 | 20 190 | 191 | 192 | 193 | Choose a directory to store files sent by other nodes 194 | 195 | 196 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 197 | 198 | 199 | 200 | 201 | 202 | 203 | Qt::Horizontal 204 | 205 | 206 | 207 | 40 208 | 20 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | Qt::Horizontal 219 | 220 | 221 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | buttonBox 231 | accepted() 232 | GuideDialog 233 | accept() 234 | 235 | 236 | 248 237 | 254 238 | 239 | 240 | 157 241 | 274 242 | 243 | 244 | 245 | 246 | buttonBox 247 | rejected() 248 | GuideDialog 249 | reject() 250 | 251 | 252 | 316 253 | 260 254 | 255 | 256 | 286 257 | 274 258 | 259 | 260 | 261 | 262 | 263 | -------------------------------------------------------------------------------- /main.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LafdupWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 541 10 | 410 11 | 12 | 13 | 14 | Sync Clipboard 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | Qt::ScrollBarAlwaysOff 25 | 26 | 27 | QAbstractScrollArea::AdjustIgnored 28 | 29 | 30 | true 31 | 32 | 33 | 34 | 35 | Qt::Vertical 36 | 37 | 38 | 39 | 40 | 300 41 | 0 42 | 43 | 44 | 45 | Send Text And Files 46 | 47 | 48 | 49 | 50 | 51 | 52 | 0 53 | 0 54 | 55 | 56 | 57 | 58 | 16777215 59 | 16777215 60 | 61 | 62 | 63 | QFrame::NoFrame 64 | 65 | 66 | Qt::ScrollBarAlwaysOff 67 | 68 | 69 | Paste Text Here! 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | Send Text [Ctrl+Enter] 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 0 87 | 0 88 | 89 | 90 | 91 | Send Files 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 0 102 | 0 103 | 104 | 105 | 106 | You Can Drag Sending Files to This Window 107 | 108 | 109 | Qt::AlignCenter 110 | 111 | 112 | true 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 0 122 | 0 123 | 124 | 125 | 126 | Configuration 127 | 128 | 129 | 130 | 131 | 132 | 133 | 0 134 | 0 135 | 136 | 137 | 138 | Other Peers: 139 | 192.168.199.2 140 | 10.1.1.2 141 | 142 | 143 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 置顶固定窗口 153 | 154 | 155 | 156 | 157 | 158 | 159 | Qt::Horizontal 160 | 161 | 162 | 163 | 40 164 | 20 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | Password && Other Configurations... 173 | 174 | 175 | 176 | :/images/configure.png:/images/configure.png 177 | 178 | 179 | Qt::ToolButtonTextBesideIcon 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | Set To &Clipboard 194 | 195 | 196 | 197 | 198 | Copy To &Remote 199 | 200 | 201 | 202 | 203 | &Show 204 | 205 | 206 | 207 | 208 | E&xit 209 | 210 | 211 | 212 | 213 | Clear All 214 | 215 | 216 | Clear All Items 217 | 218 | 219 | 220 | 221 | Remove 222 | 223 | 224 | Remove Selected Item 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /discovery.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "discovery.h" 4 | #include "peer.h" 5 | 6 | static Q_LOGGING_CATEGORY(logger, "lafdup.discovery"); 7 | using namespace qtng; 8 | const quint16 DefaultPort = 7951; 9 | const quint16 MagicNumber = DefaultPort; 10 | const quint8 CurrentVersion = 1; 11 | 12 | LafdupKcpSocket::LafdupKcpSocket(LafdupDiscovery *parent) 13 | : KcpSocket(HostAddress::IPv4Protocol) 14 | , parent(parent) 15 | { 16 | } 17 | 18 | bool LafdupKcpSocket::filter(char *data, qint32 *len, HostAddress *addr, quint16 *port) 19 | { 20 | const QByteArray &packet = QByteArray::fromRawData(data, *len); 21 | if (packet.startsWith("\x1f\x0f")) { // MagicCode 22 | parent->handleDiscoveryRequest(packet, *addr, *port); 23 | return true; 24 | } 25 | if (packet.startsWith("\xcd\x1f\x0f")) { // packet previous version sent. 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | LafdupDiscovery::LafdupDiscovery(const QByteArray &uuid, quint16 port, LafdupPeer *parent) 32 | : operations(new CoroutineGroup()) 33 | , uuid(uuid) 34 | , parent(parent) 35 | , port(port) 36 | { 37 | kcpSocket.reset(new LafdupKcpSocket(this)); 38 | kcpSocket->setOption(Socket::BroadcastSocketOption, true); 39 | } 40 | 41 | LafdupDiscovery::~LafdupDiscovery() 42 | { 43 | delete operations; 44 | } 45 | 46 | bool LafdupDiscovery::start() 47 | { 48 | if (operations->has("serve")) { 49 | if (Q_UNLIKELY(kcpSocket->state() != Socket::ListeningState)) { 50 | qCWarning(logger) << "invalid peer state, kcp socket is dead."; 51 | } 52 | if (Q_UNLIKELY(!operations->has("discovery"))) { 53 | qCWarning(logger) << "invalid peer state, discovery coroutine is dead."; 54 | } 55 | return true; 56 | } 57 | 58 | if (!kcpSocket->bind(port)) { 59 | return false; 60 | } 61 | kcpSocket->listen(50); 62 | 63 | operations->spawnWithName("serve", [this] { serve(); }); 64 | operations->spawnWithName("discovery", [this] { discovery(); }); 65 | return true; 66 | } 67 | 68 | void LafdupDiscovery::stop() 69 | { 70 | operations->killall(); 71 | kcpSocket.reset(new LafdupKcpSocket(this)); 72 | } 73 | 74 | void LafdupDiscovery::setExtraKnownPeers(const QSet> &extraKnownPeers) 75 | { 76 | this->extraKnownPeers = extraKnownPeers; 77 | } 78 | 79 | QSet> LafdupDiscovery::getExtraKnownPeers() 80 | { 81 | return extraKnownPeers; 82 | } 83 | 84 | QSet getMyIPs() 85 | { 86 | QSet addresses; 87 | const auto &list = NetworkInterface::allAddresses(); 88 | for (const HostAddress &addr : list) { 89 | addresses.insert(addr); 90 | } 91 | return addresses; 92 | } 93 | 94 | QStringList LafdupDiscovery::getAllBoundAddresses() 95 | { 96 | QStringList addresses; 97 | const auto &list = NetworkInterface::allAddresses(); 98 | for (const HostAddress &addr : list) { 99 | if (!addr.isLoopback() && !addr.isMulticast() && addr.protocol() == HostAddress::IPv4Protocol) { 100 | addresses.append(addr.toString()); 101 | } 102 | } 103 | return addresses; 104 | } 105 | 106 | quint16 LafdupDiscovery::getPort() 107 | { 108 | if (port == 0) { 109 | return kcpSocket->localPort(); 110 | } else { 111 | return port; 112 | } 113 | } 114 | 115 | quint16 LafdupDiscovery::getDefaultPort() 116 | { 117 | return DefaultPort; 118 | } 119 | 120 | QByteArray LafdupDiscovery::getUuid() 121 | { 122 | return uuid; 123 | } 124 | 125 | void LafdupDiscovery::serve() 126 | { 127 | while (true) { 128 | QSharedPointer request(kcpSocket->accept()); 129 | if (request.isNull()) { 130 | return; 131 | } 132 | parent->tryToConnectPeer(request); 133 | } 134 | } 135 | 136 | void LafdupDiscovery::handleDiscoveryRequest(const QByteArray &packet, HostAddress addr, quint16 port) 137 | { 138 | quint16 magicNumber; 139 | quint8 version; 140 | quint32 len; 141 | QByteArray uuid; 142 | 143 | QDataStream ds(packet); 144 | ds >> magicNumber >> version >> len; 145 | if (ds.status() != QDataStream::Ok) { 146 | qCInfo(logger) << "got invalid discovery packet."; 147 | return; 148 | } 149 | if (magicNumber != MagicNumber) { 150 | qCInfo(logger) << "got datagram with bad magic number: " << magicNumber; 151 | return; 152 | } 153 | if (version != CurrentVersion) { 154 | qCInfo(logger) << "version" << version << "is unknown."; 155 | return; 156 | } 157 | if (len > 64) { 158 | qCInfo(logger) << "got datagram with bad uuid length: " << len; 159 | return; 160 | } 161 | uuid.resize(static_cast(len)); 162 | 163 | ds.readRawData(uuid.data(), static_cast(len)); 164 | if (ds.status() != QDataStream::Ok) { 165 | qCInfo(logger) << "got invalid discovery packet."; 166 | return; 167 | } 168 | 169 | if (uuid.isEmpty()) { 170 | qCInfo(logger) << "got datagram with empty uuid."; 171 | return; 172 | } 173 | 174 | if (uuid == this->uuid) { 175 | return; 176 | } 177 | const QString &peerName = QString::fromUtf8(uuid); 178 | knownPeers.insert(peerName, qMakePair(addr, port)); 179 | if (parent->hasPeer(peerName)) { 180 | return; 181 | } 182 | if (parent->hasPeer(addr, port)) { 183 | return; 184 | } 185 | 186 | parent->tryToConnectPeer(peerName, addr, port); 187 | } 188 | 189 | static QSet allBroadcastAddresses() 190 | { 191 | QSet addresses; 192 | addresses.insert(HostAddress::Broadcast); 193 | const auto &listall = NetworkInterface::allInterfaces(); 194 | for (const NetworkInterface &interface : listall) { 195 | const auto &listadd = interface.addressEntries(); 196 | for (const NetworkAddressEntry &entry : listadd) { 197 | const HostAddress &addr = entry.broadcast(); 198 | if (!addr.isNull()) { 199 | addresses.insert(addr); 200 | } 201 | } 202 | } 203 | return addresses; 204 | } 205 | 206 | void LafdupDiscovery::discovery() 207 | { 208 | QByteArray packet; 209 | QDataStream ds(&packet, QIODevice::WriteOnly); 210 | ds << DefaultPort << CurrentVersion << uuid; 211 | if (ds.status() != QDataStream::Ok) { 212 | qCCritical(logger) << "can not make discovery packet."; 213 | return; 214 | } 215 | while (true) { 216 | const QSet &broadcastList = allBroadcastAddresses(); 217 | for (const HostAddress &addr : broadcastList) { 218 | qint32 bs = kcpSocket->udpSend(packet, addr, DefaultPort); 219 | if (bs != packet.size()) { 220 | qCDebug(logger) << "can not send packet to" << addr << kcpSocket->errorString(); 221 | } else { 222 | qCDebug(logger) << "send to broadcast address: " << addr.toString(); 223 | } 224 | } 225 | // prevent undefined behavior if addresses changed while broadcasting. 226 | QHash> addresses = this->knownPeers; 227 | const auto &list = addresses.keys(); 228 | for (const QString &peerName : list) { 229 | const QPair &addr = addresses.value(peerName); 230 | if (parent->hasPeer(peerName)) { 231 | continue; 232 | } 233 | if (parent->hasPeer(addr.first, addr.second)) { 234 | continue; 235 | } 236 | qint32 bs = kcpSocket->udpSend(packet, addr.first, addr.second); 237 | if (bs != packet.size()) { 238 | qCDebug(logger) << "can not send packet to" << addr << kcpSocket->errorString(); 239 | } else { 240 | qCDebug(logger) << "send to known peer: " << addr.first.toString() << ":" << addr.second; 241 | } 242 | } 243 | 244 | // prevent undefined behavior if addresses changed while broadcasting. 245 | for (const QPair &extraKnownPeer : qAsConst(this->extraKnownPeers)) { 246 | bool found = false; 247 | for (const auto &value : qAsConst(knownPeers)) { 248 | if (value == extraKnownPeer) { 249 | found = true; 250 | break; 251 | } 252 | } 253 | if (found) { 254 | continue; 255 | } 256 | if (parent->hasPeer(extraKnownPeer.first, extraKnownPeer.second)) { 257 | continue; 258 | } 259 | qint32 bs = kcpSocket->udpSend(packet, extraKnownPeer.first, extraKnownPeer.second); 260 | if (bs != packet.size()) { 261 | qCDebug(logger) << "can not send packet to" << extraKnownPeer.first.toString() << ":" 262 | << extraKnownPeer.second; 263 | } else { 264 | qCDebug(logger) << "send to extra known peer: " << extraKnownPeer.first.toString() << ":" 265 | << extraKnownPeer.second; 266 | } 267 | } 268 | Coroutine::sleep(5.0); 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /translations/lafdup_zh_CN.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ConfigureDialog 6 | 7 | 8 | Configure 9 | 配置 10 | 11 | 12 | 13 | Paste Files 14 | 复制文件 15 | 16 | 17 | 18 | Paste Text 19 | 复制文本 20 | 21 | 22 | 23 | Password 24 | 密码 25 | 26 | 27 | 28 | Peers 29 | 节点 30 | 31 | 32 | 33 | About 34 | 关于 35 | 36 | 37 | 38 | Choose a directory to receive files from other peers: 39 | 选择一个目录接收其他节点发送的文件: 40 | 41 | 42 | 43 | Browse... 44 | 浏览... 45 | 46 | 47 | 48 | Receiving files is only avaibable after this directory is selected. 49 | 只有选好目录之后才能接收文件。 50 | 51 | 52 | 53 | delete received files after several minutes to keep privacy. 54 | 在设定的分钟后删除接收的文件以保护隐私。 55 | 56 | 57 | 58 | Minutes 59 | 分钟 60 | 61 | 62 | 63 | Send copied files in clipboard 64 | 在剪贴板中发送复制的文件 65 | 66 | 67 | 68 | Only send files smaller than 69 | 只发送小于 70 | 71 | 72 | 73 | MB 74 | MB 75 | 76 | 77 | 78 | Do not copy short text to other computer/phone. 79 | 不要复制短文本到其他电脑/手机。 80 | 81 | 82 | 83 | for example: the password or other text shorter than 18 English characters. 84 | 例如:密码或其他长度小于18个英文字符的文本。 85 | 86 | 87 | 88 | <html><head/><body><p>Sync Clipboard uses AES/SHA256 to protect the data transmition between computers. All personal computers and mobile phones use the same password here. Note: this password is stored in the Windows registry in clear text. <span style=" font-weight:600;">DO NOT use the same password of your critical data.</span></p></body></html> 89 | <html><head/><body><p>同步剪贴板使用AES/SHA256来保护计算机之间的数据传输。所有的个人电脑和手机都使用相同的密码。注意:此密码以明文形式存储在Windows注册表中。 <span style=" font-weight:600;">为了数据安全对于重要数据不要使用一样的密码.</span></p></body></html> 90 | 91 | 92 | 93 | Input a password to encrypt your sending data. 94 | 输入密码加密发送数据。 95 | 96 | 97 | 98 | Sync Clipboard sends broadcast to your personal computers and mobile phones which connect to the same network as this computer. You might add the IP addresses of your other personal computers or mobile phones here, only if they connect to a different network. 99 | 同步剪贴板发送广播到您的个人电脑和移动电话连接到相同的网络,这台计算机。您可以在这里添加其他个人电脑或移动电话的IP地址,但前提是它们连接到不同的网络。 100 | 101 | 102 | 103 | 192.168.1.105 104 | 105 | 106 | 107 | 108 | &Add 109 | 添加 110 | 111 | 112 | 113 | &Remove Selected IP 114 | 移除所选IP 115 | 116 | 117 | 118 | <html><head/><body><p>Or My PayPal Link:</p><p><a href="https://paypal.me/hgoldfish"><span style=" text-decoration: underline; color:#303e4e;">https://paypal.me/hgoldfish</span></a></p></body></html> 119 | 120 | 121 | 122 | 123 | If you like this software. Might you consider paying some to supporting its development? 124 | 如果你喜欢这个软件。你会考虑出钱支持它的发展吗? 125 | 126 | 127 | 128 | © 2019-2020 Qize Huang <hgoldfish@gmail.com> 129 | 130 | 131 | 132 | 133 | Check Language: 134 | 选择语言: 135 | 136 | 137 | 138 | English 139 | 140 | 141 | 142 | 143 | 中文(简体) 144 | 145 | 146 | 147 | 148 | General 149 | 通用 150 | 151 | 152 | 153 | Whether to set the software to start automatically on startup 154 | 是否设置为开机自启动 155 | 156 | 157 | 158 | Post-start minimization 159 | 启动时最小化 160 | 161 | 162 | 163 | Select Cache Directory to Receive Files. 164 | 选择一个文件夹接收文件 165 | 166 | 167 | 168 | %1 is not a valid IP. 169 | %1 是一个无效IP 170 | 171 | 172 | 173 | CopyPasteModel 174 | 175 | 176 | 177 | <Spaces> 178 | <空格> 179 | 180 | 181 | 182 | 183 | 184 | Image 185 | 图片 186 | 187 | 188 | 189 | GuideDialog 190 | 191 | 192 | Dialog 193 | 初始化引导 194 | 195 | 196 | 197 | Password: 198 | 密码: 199 | 200 | 201 | 202 | Cannot be null 203 | 不能为空 204 | 205 | 206 | 207 | You need to set a password to ensure the security of data transmissionel 208 | Sending and receiving can only be achieved if the sender and receiver use the same password 209 | 你需要设置一个密码来保障传输的数据安全 210 | 只有当发送方和接收方使用同一个的密码时,双方才能通信 211 | 212 | 213 | 214 | Directory: 215 | 目录: 216 | 217 | 218 | 219 | Browse 220 | 选择目录 221 | 222 | 223 | 224 | Choose a directory to store files sent by other nodes 225 | 选择一个目录接收其他节点发送的文件 226 | 227 | 228 | 229 | Setting Guide 230 | 设置引导 231 | 232 | 233 | 234 | Select Cache Directory to Receive Files. 235 | 选择一个文件夹接收文件 236 | 237 | 238 | 239 | LafdupPeer 240 | 241 | 242 | Failed to send, no one accepted 243 | 发送失败,没有节点接收 244 | 245 | 246 | 247 | Sent successfully 248 | 发送成功 249 | 250 | 251 | 252 | LafdupRemoteStub 253 | 254 | 255 | 256 | The time is wrong or the content is empty 257 | 时间有误或发送内容为空 258 | 259 | 260 | 261 | 262 | 263 | The same content is sent repeatedly 264 | 内容重复发送 265 | 266 | 267 | 268 | 269 | 270 | 271 | The local file to send could not be found 272 | 找不到本地待发送的文件 273 | 274 | 275 | 276 | 277 | The storage path for the other party is empty 278 | 对方存放文件路径为空 279 | 280 | 281 | 282 | 283 | The storage path given by the other party is invalid 284 | 对方提供的存放路径无效 285 | 286 | 287 | 288 | 289 | Unable to create a folder on the other side to store files 290 | 不能在对方的路径中创建一个文件去保存文件 291 | 292 | 293 | 294 | 295 | Failed to save the file on the other party's computer 296 | 在对方电脑中保存文件失败 297 | 298 | 299 | 300 | 301 | Failed to receive the picture 302 | 接收文件失败 303 | 304 | 305 | 306 | LafdupWindow 307 | 308 | 309 | Sync Clipboard 310 | 311 | 312 | 313 | 314 | Send Text And Files 315 | 发送文本信息或文件 316 | 317 | 318 | 319 | Paste Text Here! 320 | 复制文本到这里! 321 | 322 | 323 | 324 | Send Text [Ctrl+Enter] 325 | 发送文本消息[Ctrl+Enter] 326 | 327 | 328 | 329 | Send Files 330 | 发送文件 331 | 332 | 333 | 334 | You Can Drag Sending Files to This Window 335 | 你可以拖拽文件到这个窗口 336 | 337 | 338 | 339 | Configuration 340 | 配置 341 | 342 | 343 | 344 | Other Peers: 345 | 192.168.199.2 346 | 10.1.1.2 347 | 其他节点: 348 | 192.168.199.2 349 | 10.1.1.2 350 | 351 | 352 | 353 | Password && Other Configurations... 354 | 密码&&其他配置... 355 | 356 | 357 | 358 | Set To &Clipboard 359 | 设置为&剪切板 360 | 361 | 362 | 363 | Copy To &Remote 364 | 复制到&远程 365 | 366 | 367 | 368 | &Show 369 | &展示 370 | 371 | 372 | 373 | E&xit 374 | 退出 375 | 376 | 377 | 378 | Clear All 379 | 清除所有 380 | 381 | 382 | 383 | Clear All Items 384 | 清除所有项目 385 | 386 | 387 | 388 | Remove 389 | 删除 390 | 391 | 392 | 393 | Remove Selected Item 394 | 删除选中项目 395 | 396 | 397 | 398 | Can not bind to port %1. Will not synchronize from other phone/pc. 399 | 无法绑定到端口%1。不会从其他手机或PC同步.. 400 | 401 | 402 | 403 | Sync Clipboard is minimized to tray icon. 404 | 同步剪贴板被最小化到托盘图标。 405 | 406 | 407 | 408 | can not send urls as files. this is a programming bug. 409 | 不能将url作为文件发送。这是一个编程错误. 410 | 411 | 412 | 413 | can not send files. some file is moved. 414 | 不能发送文件,某些文件被移动。 415 | 416 | 417 | 418 | Can not send empty content. 419 | 发送内容不能为空。 420 | 421 | 422 | 423 | select files to send. 424 | 选择文件发送。 425 | 426 | 427 | 428 | Start sending 429 | 开始发送 430 | 431 | 432 | 433 | 434 | save files 435 | 436 | 437 | 438 | 439 | txt file (*.txt) 440 | 441 | 442 | 443 | 444 | 445 | 错误 446 | 447 | 448 | 449 | 450 | 451 | 文件保存失败: 452 | 453 | 454 | 455 | 456 | My IP Addresses: 457 | 本机IP: 458 | 459 | 460 | 461 | 置顶固定窗口 462 | 463 | 464 | 465 | 466 | PasswordDialog 467 | 468 | 469 | Change Password 470 | 修改密码 471 | 472 | 473 | 474 | Sync Clipboard uses AES/SHA256 to protect the data transmition between computers. All personal computers and mobile phones use the same password here. Note: this password is stored in the Windows registry in clear text. DO NOT use the same password of your critical data. 475 | 同步剪贴板使用AES/SHA256来保护计算机之间的数据传输。所有的个人电脑和手机都使用相同的密码。注意:此密码以明文形式存储在Windows注册表中。不要对关键数据使用相同的密码。 476 | 477 | 478 | 479 | Password for sending content 480 | 发送内容密码 481 | 482 | 483 | 484 | Password is empty. 485 | 密码为空 486 | 487 | 488 | 489 | QObject 490 | 491 | 492 | tips 493 | 提示 494 | 495 | 496 | 497 | The program is running, please exit first if necessary 498 | 已有程序在运行,如有需要请先退出 499 | 500 | 501 | 502 | -------------------------------------------------------------------------------- /configure.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ConfigureDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 674 10 | 482 11 | 12 | 13 | 14 | Configure 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 0 24 | 0 25 | 26 | 27 | 28 | 29 | 130 30 | 16777215 31 | 32 | 33 | 34 | 35 | 40 36 | 40 37 | 38 | 39 | 40 | QListView::Static 41 | 42 | 43 | QListView::TopToBottom 44 | 45 | 46 | true 47 | 48 | 49 | -1 50 | 51 | 52 | 53 | Paste Files 54 | 55 | 56 | 57 | :/images/application-vnd.wordperfect.png:/images/application-vnd.wordperfect.png 58 | 59 | 60 | 61 | 62 | Paste Text 63 | 64 | 65 | 66 | :/images/klipper.png:/images/klipper.png 67 | 68 | 69 | 70 | 71 | Password 72 | 73 | 74 | 75 | :/images/document-encrypt.png:/images/document-encrypt.png 76 | 77 | 78 | 79 | 80 | Peers 81 | 82 | 83 | 84 | :/images/network-wireless-connected-100.png:/images/network-wireless-connected-100.png 85 | 86 | 87 | 88 | 89 | About 90 | 91 | 92 | 93 | :/images/klipper.png:/images/klipper.png 94 | 95 | 96 | 97 | 98 | General 99 | 100 | 101 | 102 | :/images/language.png:/images/language.png 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 0 112 | 0 113 | 114 | 115 | 116 | 2 117 | 118 | 119 | 120 | 121 | 122 | 123 | Choose a directory to receive files from other peers: 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | Qt::Horizontal 133 | 134 | 135 | QSizePolicy::Fixed 136 | 137 | 138 | 139 | 10 140 | 20 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 0 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | Browse... 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | Receiving files is only avaibable after this directory is selected. 168 | 169 | 170 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | false 182 | 183 | 184 | delete received files after several minutes to keep privacy. 185 | 186 | 187 | true 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | Qt::Horizontal 197 | 198 | 199 | QSizePolicy::Fixed 200 | 201 | 202 | 203 | 10 204 | 20 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | false 213 | 214 | 215 | Minutes 216 | 217 | 218 | 1 219 | 220 | 221 | 43200 222 | 223 | 224 | 30 225 | 226 | 227 | 228 | 229 | 230 | 231 | Qt::Horizontal 232 | 233 | 234 | 235 | 40 236 | 20 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | Qt::Vertical 247 | 248 | 249 | QSizePolicy::Fixed 250 | 251 | 252 | 253 | 20 254 | 10 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | Qt::Horizontal 263 | 264 | 265 | 266 | 267 | 268 | 269 | Qt::Vertical 270 | 271 | 272 | QSizePolicy::Fixed 273 | 274 | 275 | 276 | 20 277 | 10 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | Send copied files in clipboard 286 | 287 | 288 | true 289 | 290 | 291 | 292 | 293 | 294 | 295 | true 296 | 297 | 298 | Only send files smaller than 299 | 300 | 301 | true 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | Qt::Horizontal 311 | 312 | 313 | QSizePolicy::Fixed 314 | 315 | 316 | 317 | 10 318 | 20 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | true 327 | 328 | 329 | MB 330 | 331 | 332 | 1 333 | 334 | 335 | 1048576 336 | 337 | 338 | 100 339 | 340 | 341 | 342 | 343 | 344 | 345 | Qt::Horizontal 346 | 347 | 348 | 349 | 40 350 | 20 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | Qt::Vertical 361 | 362 | 363 | 364 | 20 365 | 123 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 0 378 | 379 | 380 | 381 | 382 | Do not copy short text to other computer/phone. 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | Qt::Horizontal 392 | 393 | 394 | QSizePolicy::Fixed 395 | 396 | 397 | 398 | 10 399 | 20 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | for example: the password or other text shorter than 18 English characters. 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | Qt::Vertical 419 | 420 | 421 | 422 | 20 423 | 381 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 0 437 | 0 438 | 439 | 440 | 441 | <html><head/><body><p>Sync Clipboard uses AES/SHA256 to protect the data transmition between computers. All personal computers and mobile phones use the same password here. Note: this password is stored in the Windows registry in clear text. <span style=" font-weight:600;">DO NOT use the same password of your critical data.</span></p></body></html> 442 | 443 | 444 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 445 | 446 | 447 | true 448 | 449 | 450 | 451 | 452 | 453 | 454 | QLineEdit::PasswordEchoOnEdit 455 | 456 | 457 | Input a password to encrypt your sending data. 458 | 459 | 460 | 461 | 462 | 463 | 464 | Qt::Vertical 465 | 466 | 467 | 468 | 20 469 | 296 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | Sync Clipboard sends broadcast to your personal computers and mobile phones which connect to the same network as this computer. You might add the IP addresses of your other personal computers or mobile phones here, only if they connect to a different network. 482 | 483 | 484 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 485 | 486 | 487 | true 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 192.168.1.105 497 | 498 | 499 | 500 | 501 | 502 | 503 | &Add 504 | 505 | 506 | true 507 | 508 | 509 | 510 | 511 | 512 | 513 | &Remove Selected IP 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | Qt::Vertical 530 | 531 | 532 | QSizePolicy::Fixed 533 | 534 | 535 | 536 | 20 537 | 40 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | Qt::Horizontal 548 | 549 | 550 | 551 | 40 552 | 20 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 160 562 | 200 563 | 564 | 565 | 566 | 567 | 160 568 | 200 569 | 570 | 571 | 572 | 573 | 574 | 575 | :/images/alipay_code.jpg 576 | 577 | 578 | true 579 | 580 | 581 | 582 | 583 | 584 | 585 | Qt::Horizontal 586 | 587 | 588 | QSizePolicy::Fixed 589 | 590 | 591 | 592 | 10 593 | 20 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | Qt::Vertical 602 | 603 | 604 | 605 | 606 | 607 | 608 | Qt::Horizontal 609 | 610 | 611 | QSizePolicy::Fixed 612 | 613 | 614 | 615 | 10 616 | 20 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | <html><head/><body><p>Or My PayPal Link:</p><p><a href="https://paypal.me/hgoldfish"><span style=" text-decoration: underline; color:#303e4e;">https://paypal.me/hgoldfish</span></a></p></body></html> 625 | 626 | 627 | true 628 | 629 | 630 | 631 | 632 | 633 | 634 | Qt::Horizontal 635 | 636 | 637 | 638 | 40 639 | 20 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | Qt::Vertical 650 | 651 | 652 | QSizePolicy::Fixed 653 | 654 | 655 | 656 | 20 657 | 40 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | If you like this software. Might you consider paying some to supporting its development? 666 | 667 | 668 | Qt::AlignCenter 669 | 670 | 671 | true 672 | 673 | 674 | 675 | 676 | 677 | 678 | Qt::Vertical 679 | 680 | 681 | 682 | 20 683 | 62 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | © 2019-2020 Qize Huang <hgoldfish@gmail.com> 692 | 693 | 694 | Qt::AlignCenter 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 70 705 | 70 706 | 372 707 | 141 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 0 718 | 0 719 | 720 | 721 | 722 | 723 | 80 724 | 0 725 | 726 | 727 | 728 | Check Language: 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 0 737 | 0 738 | 739 | 740 | 741 | 742 | 80 743 | 0 744 | 745 | 746 | 747 | 748 | English 749 | 750 | 751 | 752 | 753 | 中文(简体) 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | Qt::Horizontal 762 | 763 | 764 | QSizePolicy::Fixed 765 | 766 | 767 | 768 | 180 769 | 20 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | Whether to set the software to start automatically on startup 780 | 781 | 782 | 783 | 784 | 785 | 786 | Post-start minimization 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | Qt::Horizontal 801 | 802 | 803 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | buttonBox 815 | accepted() 816 | ConfigureDialog 817 | accept() 818 | 819 | 820 | 248 821 | 254 822 | 823 | 824 | 157 825 | 274 826 | 827 | 828 | 829 | 830 | buttonBox 831 | rejected() 832 | ConfigureDialog 833 | reject() 834 | 835 | 836 | 316 837 | 260 838 | 839 | 840 | 286 841 | 274 842 | 843 | 844 | 845 | 846 | lstFunctions 847 | currentRowChanged(int) 848 | stackedWidget 849 | setCurrentIndex(int) 850 | 851 | 852 | 71 853 | 219 854 | 855 | 856 | 404 857 | 219 858 | 859 | 860 | 861 | 862 | 863 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /peer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "discovery.h" 5 | #include "peer_p.h" 6 | 7 | static Q_LOGGING_CATEGORY(logger, "lafdup.peer") using namespace qtng; 8 | using namespace lafrpc; 9 | 10 | LafdupRemoteStub::LafdupRemoteStub(LafdupPeer *parent) 11 | : parent(parent) 12 | { 13 | } 14 | 15 | bool LafdupRemoteStub::pasteText(const QDateTime ×tamp, const QString &text) 16 | { 17 | if (!timestamp.isValid() || text.isEmpty()) { 18 | throw RpcRemoteException(tr("The time is wrong or the content is empty")); 19 | } 20 | if (parent->findItem(timestamp)) { 21 | throw RpcRemoteException(tr("The same content is sent repeatedly")); 22 | } 23 | CopyPaste item; 24 | item.direction = CopyPaste::Incoming; 25 | item.timestamp = timestamp; 26 | item.mimeType = TextType; 27 | item.text = text; 28 | parent->items.prepend(item); 29 | QPointer peer(parent); 30 | callInEventLoopAsync([peer, item] { 31 | if (!peer.isNull()) { 32 | emit peer->incoming(item); 33 | } 34 | }); 35 | return true; 36 | } 37 | 38 | bool LafdupRemoteStub::pasteCompText(const QDateTime ×tamp, const QString &text, const bool &isHasTextHtml) 39 | { 40 | if (!timestamp.isValid() || text.isEmpty()) { 41 | throw RpcRemoteException(tr("The time is wrong or the content is empty")); 42 | } 43 | if (parent->findItem(timestamp)) { 44 | throw RpcRemoteException(tr("The same content is sent repeatedly")); 45 | } 46 | PasteHashKey key(parent->rpc->getCurrentPeer()->name(), timestamp); 47 | CopyPaste item; 48 | item = pasteHash[key]; 49 | if (isHasTextHtml) { 50 | item.isTextHtml = 1; 51 | } else { 52 | item.isTextHtml = 0; 53 | } 54 | item.direction = CopyPaste::Incoming; 55 | item.timestamp = timestamp; 56 | item.mimeType = CompType; 57 | pasteHash[key] = item; 58 | return true; 59 | } 60 | 61 | bool LafdupRemoteStub::pasteCompImage(const QDateTime ×tamp, QSharedPointer image) 62 | { 63 | if (!timestamp.isValid() || image.isNull() || image->name().isEmpty()) { 64 | throw RpcRemoteException(tr("The local file to send could not be found")); 65 | } 66 | QString name = parent->rpc->getCurrentPeer()->name(); 67 | QByteArray imageData; 68 | bool ok = image->recvall(imageData); 69 | if (!ok) { 70 | qCDebug(logger) << "can not receive image data."; 71 | throw RpcRemoteException(tr("Failed to receive the picture")); 72 | } 73 | PasteHashKey key(name, timestamp); 74 | CopyPaste item; 75 | item = pasteHash[key]; 76 | item.direction = CopyPaste::Incoming; 77 | item.timestamp = timestamp; 78 | item.mimeType = CompType; 79 | item.image = imageData; 80 | pasteHash[key] = item; 81 | return true; 82 | } 83 | 84 | bool LafdupRemoteStub::pasteCompFiles(const QDateTime ×tamp, QSharedPointer rpcDir) 85 | { 86 | if (rpcDir.isNull() || !rpcDir->isValid()) { 87 | throw RpcRemoteException(tr("The local file to send could not be found")); 88 | } 89 | if (parent->cacheDir.isEmpty()) { 90 | throw RpcRemoteException(tr("The storage path for the other party is empty")); 91 | } 92 | QDir cacheDir(parent->cacheDir); 93 | if (!cacheDir.isReadable()) { 94 | throw RpcRemoteException(tr("The storage path given by the other party is invalid")); 95 | } 96 | const QString &subdir = timestamp.toString("yyyyMMddHHmmss"); 97 | if (!cacheDir.mkdir(subdir)) { 98 | throw RpcRemoteException(tr("Unable to create a folder on the other side to store files")); 99 | } 100 | QDir destDir(cacheDir.filePath(subdir)); 101 | QString name = parent->rpc->getCurrentPeer()->name(); 102 | bool ok = rpcDir->writeToPath(destDir.path()); 103 | if (!ok) { 104 | throw RpcRemoteException(tr("Failed to save the file on the other party's computer")); 105 | } 106 | QStringList fullPaths; 107 | for (const QString &filePath : static_cast( 108 | destDir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::System))) { 109 | fullPaths.append(destDir.absoluteFilePath(filePath)); 110 | } 111 | parent->writeInformation(destDir); 112 | PasteHashKey key(name, timestamp); 113 | CopyPaste item = pasteHash[key]; 114 | item.direction = CopyPaste::Incoming; 115 | item.timestamp = timestamp; 116 | item.mimeType = CompType; 117 | item.files = fullPaths; 118 | pasteHash[key] = item; 119 | return true; 120 | } 121 | 122 | bool LafdupRemoteStub::pasteEnd(const QDateTime &timeStamp) 123 | { 124 | PasteHashKey key(parent->rpc->getCurrentPeer()->name(), timeStamp); 125 | CopyPaste item = pasteHash[key]; 126 | if (!parent->findItem(item)) { 127 | parent->items.prepend(item); 128 | } else { 129 | return false; 130 | } 131 | QPointer parentRef(parent); 132 | callInEventLoopAsync([parentRef, item] { 133 | if (!parentRef.isNull()) { 134 | emit parentRef->incoming(item); 135 | } 136 | }); 137 | return true; 138 | } 139 | 140 | bool LafdupRemoteStub::pasteFiles(const QDateTime ×tamp, QSharedPointer rpcDir) 141 | { 142 | if (parent->findItem(timestamp) || rpcDir.isNull() || !rpcDir->isValid()) { 143 | throw RpcRemoteException(tr("The local file to send could not be found")); 144 | } 145 | if (parent->cacheDir.isEmpty()) { 146 | throw RpcRemoteException(tr("The storage path for the other party is empty")); 147 | } 148 | QDir cacheDir(parent->cacheDir); 149 | if (!cacheDir.isReadable()) { 150 | throw RpcRemoteException(tr("The storage path given by the other party is invalid")); 151 | } 152 | const QString &subdir = timestamp.toString("yyyyMMddHHmmss"); 153 | if (!cacheDir.mkdir(subdir)) { 154 | throw RpcRemoteException(tr("Unable to create a folder on the other side to store files")); 155 | } 156 | QDir destDir(cacheDir.filePath(subdir)); 157 | bool ok = rpcDir->writeToPath(destDir.path()); 158 | if (!ok) { 159 | throw RpcRemoteException(tr("Failed to save the file on the other party's computer")); 160 | } 161 | 162 | CopyPaste item; 163 | item.direction = CopyPaste::Incoming; 164 | item.timestamp = timestamp; 165 | item.mimeType = BinaryType; 166 | QStringList fullPaths; 167 | for (const QString &filePath : static_cast( 168 | destDir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::System))) { 169 | fullPaths.append(destDir.absoluteFilePath(filePath)); 170 | } 171 | item.files = fullPaths; 172 | parent->items.prepend(item); 173 | QPointer parentRef(parent); 174 | callInEventLoopAsync([parentRef, item] { 175 | if (!parentRef.isNull()) { 176 | emit parentRef->incoming(item); 177 | } 178 | }); 179 | parent->writeInformation(destDir); 180 | return true; 181 | } 182 | 183 | bool LafdupRemoteStub::pasteImage(const QDateTime ×tamp, QSharedPointer image) 184 | { 185 | if (!timestamp.isValid() || image.isNull() || image->name().isEmpty()) { 186 | throw RpcRemoteException(tr("The local file to send could not be found")); 187 | } 188 | if (parent->findItem(timestamp)) { 189 | throw RpcRemoteException(tr("The same content is sent repeatedly")); 190 | } 191 | QByteArray imageData; 192 | bool ok = image->recvall(imageData); 193 | if (!ok) { 194 | qCDebug(logger) << "can not receive image data."; 195 | throw RpcRemoteException(tr("Failed to receive the picture")); 196 | } 197 | CopyPaste item; 198 | item.timestamp = timestamp; 199 | item.mimeType = ImageType; 200 | item.image = imageData; 201 | parent->items.prepend(item); 202 | QPointer parentRef(parent); 203 | callInEventLoopAsync([parentRef, item] { 204 | if (!parentRef.isNull()) { 205 | emit parentRef->incoming(item); 206 | } 207 | }); 208 | return true; 209 | } 210 | 211 | bool LafdupRemoteStub::ping() 212 | { 213 | return true; 214 | } 215 | 216 | QDateTime LafdupRemoteStub::getCurrentTime() 217 | { 218 | return QDateTime::currentDateTime(); 219 | } 220 | 221 | LafdupPeer::LafdupPeer(const QByteArray &uuid, quint16 port) 222 | : stub(new LafdupRemoteStub(this)) 223 | , deleteFilesTime(5) 224 | , sendFilesSize(10.0) 225 | , ignorePassword(false) 226 | , cleaningFiles(false) 227 | , operations(new CoroutineGroup()) 228 | { 229 | lafrpc::registerClass(); 230 | rpc = Rpc::builder(MessagePack).myPeerName(uuid).create(); 231 | Q_ASSERT(!rpc.isNull()); 232 | rpc->registerInstance(stub, "lafdup"); 233 | discovery.reset(new LafdupDiscovery(uuid, port, this)); 234 | } 235 | 236 | LafdupPeer::~LafdupPeer() 237 | { 238 | delete operations; 239 | } 240 | 241 | bool LafdupPeer::start() 242 | { 243 | if (!discovery->start()) { 244 | return false; 245 | } 246 | const QString &serverAddress = QStringLiteral("tcp://0.0.0.0:%1").arg(discovery->getPort()); 247 | if (!rpc->startServer(serverAddress, false)) { 248 | return false; 249 | } 250 | operations->spawnWithName("clean_files", [this] { cleanFiles(); }); 251 | QPointer self(this); 252 | callInEventLoopAsync([self] { 253 | if (!self.isNull()) { 254 | emit self->stateChanged(true); 255 | } 256 | }); 257 | return true; 258 | } 259 | 260 | void LafdupPeer::stop() 261 | { 262 | const QString &serverAddress = QStringLiteral("tcp://0.0.0.0:%1").arg(discovery->getPort()); 263 | rpc->stopServer(serverAddress); 264 | discovery->stop(); 265 | operations->kill("clean_files"); 266 | QPointer self(this); 267 | callInEventLoopAsync([self] { 268 | if (!self.isNull()) { 269 | emit self->stateChanged(false); 270 | } 271 | }); 272 | } 273 | 274 | struct PopulateResult 275 | { 276 | PopulateResult() 277 | : totalSize(0) 278 | { 279 | } 280 | QList entries; 281 | quint64 totalSize; 282 | }; 283 | 284 | class VirtualRpcDirFileProvider : public lafrpc::RpcDirFileProvider 285 | { 286 | public: 287 | virtual ~VirtualRpcDirFileProvider() override; 288 | public: 289 | virtual QSharedPointer getFile(const QString &filePath, QIODevice::OpenMode mode) override; 290 | QString makePath(const QString &filePath); 291 | public: 292 | void addPath(const QString &filePath); 293 | void addFileInfo(const QFileInfo &fileInfo); 294 | PopulateResult populate(); 295 | public: 296 | QList fileInfoList; 297 | }; 298 | 299 | static bool isPassword(const QString &text) 300 | { 301 | if (text.size() > 18) { 302 | return false; 303 | } 304 | QString validChars("ABCDEFGHIJKLMNOPQRSTUVWXYZ" 305 | "abcdefghijklmnopqrstuvwxyz" 306 | "1234567890" 307 | "!@#$%^&*()-=_+,./<>?;:'\"[]{}~`\\|"); 308 | for (QChar c : text) { 309 | if (!validChars.contains(c)) { 310 | return false; 311 | } 312 | } 313 | return true; 314 | } 315 | 316 | void LafdupPeer::_outgoingSync(CopyPaste copyPaste) 317 | { 318 | if (!canSendContent(copyPaste)) { 319 | return; 320 | } 321 | const QList peerList = rpc->getAllPeerNames(); 322 | QSet peerNames(peerList.begin(), peerList.end()); 323 | if (peerNames.isEmpty()) { 324 | emit sendFeedBack(tr("Failed to send, no one accepted")); 325 | return; 326 | } 327 | emit sendAction(); 328 | QList> coroutines; 329 | QList> errorStrings; 330 | for (const QString &peerName : qAsConst(peerNames)) { 331 | QSharedPointer peer = rpc->get(peerName); 332 | QSharedPointer errorString(new QString()); 333 | QSharedPointer c = operations->spawn( 334 | [this, peer, copyPaste, errorString] { sendContentToPeer(peer, copyPaste, errorString.data()); }); 335 | if (c) { 336 | coroutines.append(c); 337 | errorStrings.append(errorString); 338 | } 339 | } 340 | for (QSharedPointer c : coroutines) { 341 | c->join(); 342 | } 343 | QStringList errors; 344 | for (const QSharedPointer &errorString : qAsConst(errorStrings)) { 345 | if (errorString->isEmpty()) { 346 | continue; 347 | } 348 | errors.append(*errorString); 349 | } 350 | if (errors.isEmpty()) { 351 | emit sendFeedBack(tr("Sent successfully")); 352 | if (!findItem(copyPaste)) { 353 | items.prepend(copyPaste); 354 | emit incoming(copyPaste); 355 | } 356 | } else { 357 | emit sendFeedBack(errors.join("\n")); 358 | } 359 | } 360 | 361 | bool LafdupPeer::canSendContent(const CopyPaste ©Paste) 362 | { 363 | if (copyPaste.mimeType == TextType) { 364 | if (!copyPaste.ignoreLimits && ignorePassword && isPassword(copyPaste.text)) { 365 | return false; 366 | } 367 | } else if (copyPaste.mimeType == BinaryType) { 368 | if (!copyPaste.ignoreLimits && qFuzzyIsNull(sendFilesSize)) { 369 | return false; 370 | } 371 | QSharedPointer provider(new VirtualRpcDirFileProvider()); 372 | for (const QString &filePath : copyPaste.files) { 373 | provider->addPath(filePath); 374 | } 375 | 376 | PopulateResult populateResult = provider->populate(); 377 | if (!copyPaste.ignoreLimits && populateResult.totalSize >= static_cast(sendFilesSize * 1024 * 1024)) { 378 | return false; 379 | } 380 | } else if (copyPaste.mimeType == ImageType) { 381 | QByteArray imageData = copyPaste.image; 382 | if (imageData.isEmpty()) { 383 | return false; 384 | } 385 | } else if (copyPaste.mimeType == CompType) { 386 | if (copyPaste.text.isEmpty() && copyPaste.image.isEmpty() && copyPaste.files.isEmpty()) { 387 | return false; 388 | } 389 | if (!copyPaste.text.isEmpty()) { 390 | if (!copyPaste.ignoreLimits && ignorePassword && isPassword(copyPaste.text)) { 391 | return false; 392 | } 393 | } 394 | if (!copyPaste.files.isEmpty()) { 395 | if (!copyPaste.ignoreLimits && qFuzzyIsNull(sendFilesSize)) { 396 | return false; 397 | } 398 | QSharedPointer provider(new VirtualRpcDirFileProvider()); 399 | for (const QString &filePath : copyPaste.files) { 400 | provider->addPath(filePath); 401 | } 402 | 403 | PopulateResult populateResult = provider->populate(); 404 | if (!copyPaste.ignoreLimits 405 | && populateResult.totalSize >= static_cast(sendFilesSize * 1024 * 1024)) { 406 | return false; 407 | } 408 | } 409 | } else { 410 | return false; 411 | } 412 | return true; 413 | } 414 | 415 | void LafdupPeer::outgoing(const CopyPaste ©Paste) 416 | { 417 | if (findItem(copyPaste.timestamp)) { 418 | return; 419 | } 420 | operations->spawn([this, copyPaste]() { _outgoingSync(copyPaste); }); 421 | } 422 | 423 | QString makeAddress(const QString &prefix, const HostAddress &addr, quint16 port) 424 | { 425 | if (addr.protocol() == HostAddress::IPv6Protocol) { 426 | return QStringLiteral("%1://[%2]:%3").arg(prefix, addr.toString()).arg(port); 427 | } else { 428 | return QStringLiteral("%1://%2:%3").arg(prefix, addr.toString()).arg(port); 429 | } 430 | } 431 | 432 | bool LafdupPeer::hasPeer(const HostAddress &remoteHost, quint16 port) 433 | { 434 | const QString &kcpAddress = makeAddress("kcp", remoteHost, port); 435 | const QString &tcpAddress = makeAddress("tcp", remoteHost, port); 436 | for (const QSharedPointer &peer : static_cast>>(rpc->getAllPeers())) { 437 | if (peer->address() == kcpAddress || peer->address() == tcpAddress) { 438 | return true; 439 | } 440 | } 441 | return false; 442 | } 443 | 444 | bool LafdupPeer::hasPeer(const QString &peerName) 445 | { 446 | return !rpc->get(peerName).isNull(); 447 | } 448 | 449 | void LafdupPeer::tryToConnectPeer(QString itsPeerName, HostAddress remoteHost, quint16 port) 450 | { 451 | operations->spawn([this, itsPeerName, remoteHost, port] { 452 | for (QSharedPointer oldPeer : static_cast>>(rpc->getAll(itsPeerName))) { 453 | if (!oldPeer.isNull()) { 454 | try { 455 | oldPeer->call("lafdup.ping"); 456 | break; 457 | } catch (RpcException &) { 458 | oldPeer->close(); 459 | } 460 | } 461 | } 462 | const QString &tcpAddress = makeAddress("tcp", remoteHost, port); 463 | if (connectingPeers.contains(tcpAddress)) { 464 | return; 465 | } 466 | connectingPeers.insert(tcpAddress); 467 | 468 | QSharedPointer peer; 469 | try { 470 | Timeout timeout(5.0); 471 | QSharedPointer request = QSharedPointer(Socket::createConnection(remoteHost, port)); 472 | if (!request.isNull()) { 473 | peer = handleRequestSync(asSocketLike(request), qtng::PositivePole, itsPeerName, tcpAddress); 474 | if (!peer.isNull() && peer->name() != itsPeerName) { 475 | peer->close(); 476 | peer.clear(); 477 | } 478 | } 479 | connectingPeers.remove(tcpAddress); 480 | } catch (TimeoutException &) { 481 | connectingPeers.remove(tcpAddress); 482 | // pass and go on. 483 | } 484 | 485 | if (!peer.isNull()) { 486 | return; 487 | } 488 | 489 | const QString &kcpAddress = makeAddress("kcp", remoteHost, port); 490 | if (connectingPeers.contains(kcpAddress)) { 491 | return; 492 | } 493 | connectingPeers.insert(kcpAddress); 494 | try { 495 | Timeout timeout(5.0); 496 | QSharedPointer kcpSocket(new KcpSocket(HostAddress::IPv4Protocol)); 497 | kcpSocket->setOption(Socket::BroadcastSocketOption, true); 498 | if (kcpSocket->connect(remoteHost, port)) { 499 | handleKcpRequestSync(kcpSocket, PositivePole, itsPeerName); 500 | } 501 | connectingPeers.remove(kcpAddress); 502 | } catch (...) { 503 | connectingPeers.remove(kcpAddress); 504 | throw; 505 | } 506 | }); 507 | } 508 | 509 | void LafdupPeer::tryToConnectPeer(QSharedPointer request) 510 | { 511 | operations->spawn([this, request] { handleKcpRequestSync(request, NegativePole, QString()); }); 512 | } 513 | 514 | void LafdupPeer::handleKcpRequestSync(QSharedPointer request, DataChannelPole pole, 515 | const QString &itsPeerName) 516 | { 517 | const QString &address = makeAddress("kcp", request->peerAddress(), request->peerPort()); 518 | request->setSendQueueSize(1024); 519 | request->setMode(KcpSocket::Ethernet); 520 | handleRequestSync(asSocketLike(request), pole, itsPeerName, address); 521 | } 522 | 523 | QSharedPointer LafdupPeer::handleRequestSync(QSharedPointer request, qtng::DataChannelPole pole, 524 | const QString &itsPeerName, const QString &itsAddress) 525 | { 526 | QSharedPointer channel; 527 | if (!cipher.isNull()) { 528 | QSharedPointer encryptedChannel = encrypted(cipher, request); 529 | channel.reset(new SocketChannel(encryptedChannel, pole)); 530 | } else { 531 | channel.reset(new SocketChannel(request, pole)); 532 | } 533 | QSharedPointer peer; 534 | try { 535 | qtng::Timeout timeout(5.0); 536 | Q_UNUSED(timeout); 537 | qCDebug(logger) << "got kcp peer:" << itsAddress << pole; 538 | peer = rpc->preparePeer(channel, itsPeerName, itsAddress); 539 | qCDebug(logger) << "got rpc peer:" << !peer.isNull(); 540 | } catch (TimeoutException &) { 541 | qCDebug(logger) << "got rpc peer timeout:" << false; 542 | } 543 | return peer; 544 | } 545 | 546 | void LafdupPeer::setExtraKnownPeers(const QSet> &extraKnownPeers) 547 | { 548 | discovery->setExtraKnownPeers(extraKnownPeers); 549 | } 550 | 551 | void LafdupPeer::setPassword(QByteArray password) 552 | { 553 | operations->spawn([this, password] { 554 | cipher.reset(new Cipher(Cipher::AES256, Cipher::CFB, Cipher::Encrypt)); 555 | QByteArray salt("3.14159265358979323846"); 556 | cipher->setPassword(password, salt); 557 | if (!cipher->isValid()) { 558 | return; 559 | } 560 | for (QSharedPointer peer : static_cast>>(rpc->getAllPeers())) { 561 | peer->close(); 562 | } 563 | }); 564 | } 565 | 566 | void LafdupPeer::setCacheDir(const QString &cacheDir) 567 | { 568 | if (!this->cacheDir.isEmpty() && this->cacheDir != cacheDir) { 569 | QDir cacheDir(this->cacheDir); 570 | if (cacheDir.isReadable()) { 571 | operations->spawn([this, cacheDir] { _cleanFiles(cacheDir, true); }); 572 | } 573 | } 574 | this->cacheDir = cacheDir; 575 | } 576 | 577 | void LafdupPeer::setDeleteFilesTime(int minutes) 578 | { 579 | if (minutes >= 0) { 580 | this->deleteFilesTime = minutes; 581 | } else { 582 | this->deleteFilesTime = 0; 583 | } 584 | } 585 | 586 | void LafdupPeer::setSendFilesSize(float mb) 587 | { 588 | if (mb < 0) { 589 | this->sendFilesSize = 0.0; 590 | } else { 591 | this->sendFilesSize = mb; 592 | } 593 | } 594 | 595 | void LafdupPeer::setIgnorePassword(bool ignorePassword) 596 | { 597 | this->ignorePassword = ignorePassword; 598 | } 599 | 600 | QStringList LafdupPeer::getAllBoundAddresses() 601 | { 602 | return discovery->getAllBoundAddresses(); 603 | } 604 | 605 | quint16 LafdupPeer::getPort() 606 | { 607 | return discovery->getPort(); 608 | } 609 | 610 | quint16 LafdupPeer::getDefaultPort() 611 | { 612 | return LafdupDiscovery::getDefaultPort(); 613 | } 614 | 615 | bool LafdupPeer::findItem(const QDateTime ×tamp) 616 | { 617 | for (const CopyPaste &item : qAsConst(items)) { 618 | if (qAbs(item.timestamp.msecsTo(timestamp)) <= 50) { 619 | return true; 620 | } 621 | } 622 | return false; 623 | } 624 | 625 | bool LafdupPeer::findItem(const CopyPaste ¤tItem) 626 | { 627 | for (const CopyPaste &item : qAsConst(items)) { 628 | if (item.text == currentItem.text && item.image == currentItem.image && item.files == currentItem.files 629 | && qAbs(item.timestamp.msecsTo(currentItem.timestamp)) <= 50) { 630 | return true; 631 | } 632 | } 633 | return false; 634 | } 635 | 636 | void LafdupPeer::writeInformation(const QDir destDir) 637 | { 638 | const QString &iniFilePath = destDir.filePath("lafdup.ini"); 639 | QSettings settings(iniFilePath, QSettings::IniFormat); 640 | settings.setIniCodec("UTF-8"); 641 | settings.beginGroup("clean_files"); 642 | settings.setValue("created", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); 643 | } 644 | 645 | void LafdupPeer::cleanFiles() 646 | { 647 | while (true) { 648 | if (this->cacheDir.isEmpty()) { 649 | Coroutine::sleep(30.0); 650 | continue; 651 | } 652 | QDir cacheDir(this->cacheDir); 653 | if (!cacheDir.isReadable()) { 654 | Coroutine::sleep(30.0); 655 | continue; 656 | } 657 | _cleanFiles(cacheDir, false); 658 | try { 659 | Coroutine::sleep(30.0); 660 | } catch (CoroutineException &) { 661 | return; 662 | } 663 | } 664 | } 665 | 666 | void LafdupPeer::_cleanFiles(const QDir &dir, bool cleanAll) 667 | { 668 | if (!cleanAll && deleteFilesTime == 0) { 669 | return; 670 | } 671 | if (cleaningFiles) { 672 | return; 673 | } 674 | QScopedValueRollback svr(cleaningFiles, true); 675 | const QDateTime &now = QDateTime::currentDateTime(); 676 | for (const QFileInfo &fileInfo : 677 | static_cast(dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot))) { 678 | if (!fileInfo.isWritable()) { 679 | continue; 680 | } 681 | QSharedPointer subdir(new QDir(fileInfo.filePath())); 682 | const QString &iniFilePath = subdir->filePath("lafdup.ini"); 683 | if (!QFileInfo::exists(iniFilePath)) { 684 | continue; 685 | } 686 | if (!cleanAll) { 687 | Q_ASSERT(deleteFilesTime != 0); 688 | QSettings settings(iniFilePath, QSettings::IniFormat); 689 | settings.beginGroup("clean_files"); 690 | const QDateTime ×tamp = 691 | QDateTime::fromString(settings.value("created", now).toString(), "yyyy-MM-dd hh:mm:ss"); 692 | if (!timestamp.isValid()) { 693 | continue; 694 | } 695 | qCDebug(logger) << "want to clean deprecated files:" << now << timestamp << timestamp.msecsTo(now) << (deleteFilesTime * 60 * 1000); 696 | if (timestamp.msecsTo(now) < (deleteFilesTime * 60 * 1000)) { 697 | qCDebug(logger) << "skip directory" << subdir->path(); 698 | continue; 699 | } 700 | } 701 | callInThread([subdir] { 702 | if (!subdir->removeRecursively()) { 703 | qCDebug(logger) << "can not remove directory:" << subdir; 704 | } else { 705 | qCDebug(logger) << "remove directory:" << subdir << " sucess"; 706 | } 707 | }); 708 | } 709 | } 710 | 711 | bool LafdupPeer::sendContentToPeer(QSharedPointer peer, const CopyPaste ©Paste, QString *errorString) 712 | { 713 | float seconds = 20.0; 714 | if (copyPaste.mimeType == BinaryType) { 715 | if (copyPaste.ignoreLimits) { 716 | seconds = 60.0 * 60 * 24; // one day! 717 | } else { 718 | seconds = 60.0 * 60; // one hour 719 | } 720 | } 721 | Timeout timeout(seconds); 722 | Q_UNUSED(timeout); 723 | bool result = false; 724 | if (copyPaste.mimeType == TextType) { 725 | try { 726 | result = peer->call("lafdup.pasteText", copyPaste.timestamp, copyPaste.text).toBool(); 727 | } catch (RpcException &e) { 728 | *errorString = e.what(); 729 | } catch (TimeoutException &e) { 730 | *errorString = e.what(); 731 | } 732 | } else if (copyPaste.mimeType == BinaryType) { 733 | QSharedPointer provider(new VirtualRpcDirFileProvider()); 734 | for (const QString &filePath : copyPaste.files) { 735 | provider->addPath(filePath); 736 | } 737 | PopulateResult populateResult = provider->populate(); 738 | QSharedPointer rpcDir(new RpcDir()); 739 | rpcDir->setName("paste"); 740 | rpcDir->setEntries(populateResult.entries); 741 | rpcDir->setSize(populateResult.totalSize); 742 | QSharedPointer t = operations->spawn([rpcDir, provider] { rpcDir->readFrom(provider); }); 743 | try { 744 | result = peer->call("lafdup.pasteFiles", copyPaste.timestamp, QVariant::fromValue(rpcDir)).toBool(); 745 | } catch (RpcException &e) { 746 | *errorString = e.what(); 747 | } catch (TimeoutException &e) { 748 | *errorString = e.what(); 749 | } 750 | t->kill(); 751 | } else if (copyPaste.mimeType == ImageType) { 752 | QByteArray imageData = copyPaste.image; 753 | QSharedPointer rpcFile(new RpcFile()); 754 | rpcFile->setName("image.png"); 755 | rpcFile->setSize(static_cast(imageData.size())); 756 | QSharedPointer t = operations->spawn([rpcFile, imageData] { rpcFile->sendall(imageData); }); 757 | try { 758 | result = peer->call("lafdup.pasteImage", copyPaste.timestamp, QVariant::fromValue(rpcFile)).toBool(); 759 | } catch (RpcException &e) { 760 | *errorString = e.what(); 761 | return false; 762 | } catch (TimeoutException &e) { 763 | *errorString = e.what(); 764 | return false; 765 | } 766 | t->kill(); 767 | } else if (copyPaste.mimeType == CompType) { 768 | if (!copyPaste.text.isEmpty()) { 769 | QString text = copyPaste.text; 770 | try { 771 | result = peer->call("lafdup.pasteCompText", copyPaste.timestamp, text, copyPaste.isTextHtml).toBool(); 772 | } catch (RpcException &e) { 773 | *errorString = e.what(); 774 | return false; 775 | } catch (TimeoutException &e) { 776 | *errorString = e.what(); 777 | return false; 778 | } 779 | } 780 | if (!copyPaste.image.isNull()) { 781 | QByteArray imageData = copyPaste.image; 782 | QSharedPointer rpcFile(new RpcFile()); 783 | rpcFile->setName("image.png"); 784 | rpcFile->setSize(static_cast(imageData.size())); 785 | QSharedPointer t1 = operations->spawn([rpcFile, imageData] { rpcFile->sendall(imageData); }); 786 | try { 787 | result = peer->call("lafdup.pasteCompImage", copyPaste.timestamp, QVariant::fromValue(rpcFile)).toBool(); 788 | } catch (RpcException &e) { 789 | *errorString = e.what(); 790 | return false; 791 | } catch (TimeoutException &e) { 792 | *errorString = e.what(); 793 | return false; 794 | } 795 | } 796 | if (!copyPaste.files.isEmpty()) { 797 | QSharedPointer provider(new VirtualRpcDirFileProvider()); 798 | for (const QString &filePath : copyPaste.files) { 799 | provider->addPath(filePath); 800 | } 801 | PopulateResult populateResult = provider->populate(); 802 | QSharedPointer rpcDir(new RpcDir()); 803 | rpcDir->setName("paste"); 804 | rpcDir->setEntries(populateResult.entries); 805 | rpcDir->setSize(populateResult.totalSize); 806 | QSharedPointer t2 = operations->spawn([rpcDir, provider] { rpcDir->readFrom(provider); }); 807 | try { 808 | result = peer->call("lafdup.pasteCompFiles", copyPaste.timestamp, QVariant::fromValue(rpcDir)).toBool(); 809 | } catch (RpcException &e) { 810 | *errorString = e.what(); 811 | return false; 812 | } catch (TimeoutException &e) { 813 | *errorString = e.what(); 814 | return false; 815 | } 816 | } 817 | try { 818 | result = peer->call("lafdup.pasteEnd", copyPaste.timestamp).toBool(); 819 | } catch (RpcException &e) { 820 | *errorString = e.what(); 821 | return false; 822 | } catch (TimeoutException &e) { 823 | *errorString = e.what(); 824 | return false; 825 | } 826 | } 827 | return result; 828 | } 829 | 830 | VirtualRpcDirFileProvider::~VirtualRpcDirFileProvider() { } 831 | 832 | QSharedPointer VirtualRpcDirFileProvider::getFile(const QString &filePath, QIODevice::OpenMode mode) 833 | { 834 | Q_ASSERT(mode == QIODevice::ReadOnly); 835 | const QString &fullFilePath = makePath(filePath); 836 | if (fullFilePath.isEmpty()) { 837 | return QSharedPointer(); 838 | } else { 839 | QSharedPointer file(new QFile(fullFilePath)); 840 | if (file->open(mode)) { 841 | return FileLike::rawFile(file); 842 | } else { 843 | return QSharedPointer(); 844 | } 845 | } 846 | } 847 | 848 | QString VirtualRpcDirFileProvider::makePath(const QString &filePath) 849 | { 850 | if (filePath.isEmpty()) { 851 | return QString(); 852 | } 853 | const QStringList &parts = filePath.split("/"); 854 | Q_ASSERT(!parts.isEmpty()); 855 | const QString &name = parts.at(0); 856 | const QStringList &subpaths = parts.mid(1); 857 | 858 | for (const QFileInfo &fileInfo : qAsConst(this->fileInfoList)) { 859 | if (fileInfo.fileName() == name) { 860 | QString path = fileInfo.filePath(); 861 | if (subpaths.isEmpty()) { 862 | return path; 863 | } else { 864 | if (!fileInfo.isDir()) { 865 | qCDebug(logger) << "invalid path:" << filePath; 866 | } else { 867 | QDir dir(path); 868 | return dir.filePath(subpaths.join("/")); 869 | } 870 | } 871 | } 872 | } 873 | return QString(); 874 | } 875 | 876 | void VirtualRpcDirFileProvider::addPath(const QString &filePath) 877 | { 878 | QFileInfo fileInfo(filePath); 879 | if (fileInfo.isReadable()) { 880 | fileInfoList.append(fileInfo); 881 | } 882 | } 883 | 884 | void VirtualRpcDirFileProvider::addFileInfo(const QFileInfo &fileInfo) 885 | { 886 | if (fileInfo.isReadable()) { 887 | fileInfoList.append(fileInfo); 888 | } 889 | } 890 | 891 | static void _populate(const QDir &dir, const QString &relativePath, PopulateResult &result) 892 | { 893 | QDir::Filters filters = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Readable | QDir::Hidden; 894 | // QDir::Filters filters = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot; 895 | for (const QFileInfo &fileInfo : static_cast(dir.entryInfoList(filters, QDir::DirsFirst))) { 896 | RpcDirFileEntry entry; 897 | const QString &name = fileInfo.fileName(); 898 | if (Q_UNLIKELY(name.contains("/"))) { 899 | continue; 900 | } 901 | entry.path = relativePath.isEmpty() ? name : relativePath + "/" + name; 902 | quint64 size = static_cast(fileInfo.size()); 903 | if (fileInfo.isSymLink()) { 904 | QFile file(fileInfo.absoluteFilePath()); 905 | file.open(QIODevice::ReadOnly); 906 | size = static_cast(file.size()); 907 | file.close(); 908 | } 909 | entry.size = size; 910 | entry.isdir = fileInfo.isDir(); 911 | #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) 912 | entry.created = fileInfo.birthTime(); 913 | #else 914 | entry.created = fileInfo.created(); 915 | #endif 916 | entry.lastModified = fileInfo.lastModified(); 917 | entry.lastAccess = fileInfo.lastRead(); 918 | result.entries.append(entry); 919 | result.totalSize += entry.size; 920 | if (fileInfo.isDir()) { 921 | _populate(QDir(fileInfo.filePath()), entry.path, result); 922 | } 923 | } 924 | } 925 | 926 | static PopulateResult populate(const QDir &dir, const QString &name) 927 | { 928 | PopulateResult result; 929 | _populate(dir, name, result); 930 | return result; 931 | } 932 | 933 | PopulateResult VirtualRpcDirFileProvider::populate() 934 | { 935 | PopulateResult result; 936 | for (const QFileInfo &fileInfo : qAsConst(fileInfoList)) { 937 | if (fileInfo.isDir()) { 938 | QString name = fileInfo.fileName(); 939 | RpcDirFileEntry entry; 940 | entry.path = name; 941 | entry.size = 0; 942 | entry.isdir = true; 943 | #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) 944 | entry.created = fileInfo.birthTime(); 945 | #else 946 | entry.created = fileInfo.created(); 947 | #endif 948 | entry.lastModified = fileInfo.lastModified(); 949 | entry.lastAccess = fileInfo.lastRead(); 950 | result.entries.append(entry); 951 | 952 | QDir dir(fileInfo.filePath()); 953 | PopulateResult part = qtng::callInThread([dir, name] { return ::populate(dir, name); }); 954 | result.entries.append(part.entries); 955 | result.totalSize += part.totalSize; 956 | } else if (fileInfo.isFile()) { 957 | RpcDirFileEntry entry; 958 | const QString &name = fileInfo.fileName(); 959 | if (Q_UNLIKELY(name.contains("/"))) { 960 | continue; 961 | } 962 | quint64 size = static_cast(fileInfo.size()); 963 | if (fileInfo.isSymLink()) { 964 | QFile file(fileInfo.absoluteFilePath()); 965 | file.open(QIODevice::ReadOnly); 966 | size = static_cast(file.size()); 967 | file.close(); 968 | } 969 | entry.path = name; 970 | entry.size = size; 971 | entry.isdir = fileInfo.isDir(); 972 | #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) 973 | entry.created = fileInfo.birthTime(); 974 | #else 975 | entry.created = fileInfo.created(); 976 | #endif 977 | entry.lastModified = fileInfo.lastModified(); 978 | entry.lastAccess = fileInfo.lastRead(); 979 | result.entries.append(entry); 980 | result.totalSize += entry.size; 981 | } else { 982 | qWarning() << "unknown file type:" << fileInfo.path(); 983 | } 984 | } 985 | return result; 986 | } 987 | --------------------------------------------------------------------------------