| @@ -54,7 +54,9 @@ SOURCES += main.cpp\ | |||
| chooseemojidlg.cpp \ | |||
| platformdepend.cpp \ | |||
| chooseemojiwidget.cpp \ | |||
| sendtextedit.cpp | |||
| sendtextedit.cpp \ | |||
| feiqwin.cpp \ | |||
| plugin/unreadchecker.cpp | |||
| HEADERS += mainwindow.h \ | |||
| @@ -88,7 +90,10 @@ HEADERS += mainwindow.h \ | |||
| chooseemojidlg.h \ | |||
| platformdepend.h \ | |||
| chooseemojiwidget.h \ | |||
| sendtextedit.h | |||
| sendtextedit.h \ | |||
| plugin/iplugin.h \ | |||
| feiqwin.h \ | |||
| plugin/unreadchecker.h | |||
| FORMS += mainwindow.ui \ | |||
| searchfellowdlg.ui \ | |||
| @@ -0,0 +1,65 @@ | |||
| #include "feiqwin.h" | |||
| #include "mainwindow.h" | |||
| #include "plugin/iplugin.h" | |||
| #include "plugin/unreadchecker.h" | |||
| FeiqWin::FeiqWin() | |||
| { | |||
| } | |||
| RecvTextEdit *FeiqWin::recvTextEdit() | |||
| { | |||
| return mMainWin->mRecvTextEdit; | |||
| } | |||
| SendTextEdit *FeiqWin::sendTextEdit() | |||
| { | |||
| return mMainWin->mSendTextEdit; | |||
| } | |||
| FellowListWidget *FeiqWin::fellowListWidget() | |||
| { | |||
| return &(mMainWin->mFellowList); | |||
| } | |||
| const FeiqModel *FeiqWin::feiqModel() | |||
| { | |||
| return &(mMainWin->mFeiq.getModel()); | |||
| } | |||
| QSettings *FeiqWin::settings() | |||
| { | |||
| return mMainWin->mSettings; | |||
| } | |||
| int FeiqWin::getUnreadCount() | |||
| { | |||
| return mMainWin->getUnreadCount(); | |||
| } | |||
| void FeiqWin::init(MainWindow *mainWin) | |||
| { | |||
| mMainWin = mainWin; | |||
| loadPlugins(); | |||
| for (auto plugin : mPlugins) | |||
| plugin->init(this); | |||
| } | |||
| void FeiqWin::unInit() | |||
| { | |||
| for (auto plugin : mPlugins) | |||
| { | |||
| plugin->unInit(); | |||
| delete plugin; | |||
| } | |||
| mPlugins.clear(); | |||
| } | |||
| void FeiqWin::loadPlugins() | |||
| { | |||
| mPlugins.append(new UnreadChecker()); | |||
| } | |||
| @@ -0,0 +1,43 @@ | |||
| #ifndef FEIQWIN_H | |||
| #define FEIQWIN_H | |||
| #include "recvtextedit.h" | |||
| #include "sendtextedit.h" | |||
| #include "qsettings.h" | |||
| #include "fellowlistwidget.h" | |||
| #include "feiqlib/feiqmodel.h" | |||
| class MainWindow; | |||
| class IPlugin; | |||
| /** | |||
| * @brief The FeiqWin class | |||
| * 其实就是MainWindow的代言人,用来隔离插件和MainWindow,方便控制MainWindow对插件的可见性 | |||
| */ | |||
| class FeiqWin | |||
| { | |||
| public: | |||
| FeiqWin(); | |||
| public: | |||
| RecvTextEdit* recvTextEdit(); | |||
| SendTextEdit* sendTextEdit(); | |||
| FellowListWidget* fellowListWidget(); | |||
| const FeiqModel* feiqModel(); | |||
| QSettings* settings(); | |||
| public: | |||
| int getUnreadCount(); | |||
| private: | |||
| void init(MainWindow* mainWin); | |||
| void unInit(); | |||
| void loadPlugins(); | |||
| private: | |||
| friend class MainWindow; | |||
| MainWindow* mMainWin; | |||
| QList<IPlugin*> mPlugins; | |||
| }; | |||
| #endif // FEIQWIN_H | |||
| @@ -1,21 +1,16 @@ | |||
| #include "mainwindow.h" | |||
| #include <QApplication> | |||
| #include <QWindow> | |||
| #include "feiqwin.h" | |||
| //待测: | |||
| //*无当前交谈用户,且有未读消息时,未读消息能否正确置顶? | |||
| //应用图标 | |||
| int main(int argc, char *argv[]) | |||
| { | |||
| QApplication a(argc, argv); | |||
| a.setWindowIcon(QIcon(":/default/res/icon.png")); | |||
| MainWindow w; | |||
| FeiqWin feiqWin; | |||
| w.setFeiqWin(&feiqWin); | |||
| w.show(); | |||
| return a.exec(); | |||
| } | |||
| //表情->html | |||
| //查通讯录功能 | |||
| //查ip占用功能 | |||
| //美化用户列表 | |||
| @@ -11,6 +11,7 @@ | |||
| #include "addfellowdialog.h" | |||
| #include <QProcess> | |||
| #include "platformdepend.h" | |||
| #include "feiqwin.h" | |||
| MainWindow::MainWindow(QWidget *parent) : | |||
| QMainWindow(parent), | |||
| @@ -68,10 +69,6 @@ MainWindow::MainWindow(QWidget *parent) : | |||
| mTitle = mSettings->value("app/title", "mac飞秋").toString(); | |||
| setWindowTitle(mTitle); | |||
| mUnreadTimerInterval = mSettings->value("app/unread_timer", "0").toInt(); | |||
| if (mUnreadTimerInterval > 0) | |||
| mUnreadTimerId = startTimer(mUnreadTimerInterval*1000, Qt::VeryCoarseTimer); | |||
| //初始化飞秋引擎 | |||
| connect(this, SIGNAL(feiqViewEvent(shared_ptr<ViewEvent>)), this, SLOT(handleFeiqViewEvent(shared_ptr<ViewEvent>))); | |||
| @@ -90,6 +87,12 @@ MainWindow::~MainWindow() | |||
| delete ui; | |||
| } | |||
| void MainWindow::setFeiqWin(FeiqWin *feiqWin) | |||
| { | |||
| mFeiqWin = feiqWin; | |||
| mFeiqWin->init(this); | |||
| } | |||
| void MainWindow::enterEvent(QEvent *event) | |||
| { | |||
| auto fellow = mRecvTextEdit->curFellow(); | |||
| @@ -102,16 +105,6 @@ void MainWindow::enterEvent(QEvent *event) | |||
| PlatformDepend::instance().hideAllNotify(); | |||
| } | |||
| void MainWindow::timerEvent(QTimerEvent *event) | |||
| { | |||
| if (event->timerId() == mUnreadTimerId) | |||
| { | |||
| auto count = getUnreadCount(); | |||
| if (count > 0) | |||
| PlatformDepend::instance().showNotify("未读提醒", QString("还有%1条未读消息").arg(count)); | |||
| } | |||
| } | |||
| void MainWindow::openChartTo(const Fellow *fellow) | |||
| { | |||
| mFellowList.top(*fellow); | |||
| @@ -19,18 +19,22 @@ namespace Ui { | |||
| class MainWindow; | |||
| } | |||
| class FeiqWin; | |||
| Q_DECLARE_METATYPE(shared_ptr<ViewEvent>) | |||
| class MainWindow : public QMainWindow, IFeiqView | |||
| { | |||
| Q_OBJECT | |||
| friend class FeiqWin; | |||
| public: | |||
| explicit MainWindow(QWidget *parent = 0); | |||
| ~MainWindow(); | |||
| void setFeiqWin(FeiqWin* feiqWin); | |||
| protected: | |||
| void enterEvent(QEvent *event); | |||
| void timerEvent(QTimerEvent *event); | |||
| signals: | |||
| void showErrorAndQuit(const QString& text); | |||
| @@ -92,9 +96,7 @@ private: | |||
| SendTextEdit* mSendTextEdit; | |||
| QString mTitle; | |||
| unordered_map<const Fellow*, list<shared_ptr<ViewEvent>>> mUnreadEvents; | |||
| int mUnreadTimerInterval; | |||
| int mUnreadTimerId; | |||
| FeiqWin* mFeiqWin = nullptr; | |||
| }; | |||
| #endif // MAINWINDOW_H | |||
| @@ -0,0 +1,21 @@ | |||
| #ifndef IPLUGIN_H | |||
| #define IPLUGIN_H | |||
| #include "../feiqwin.h" | |||
| class IPlugin | |||
| { | |||
| public: | |||
| virtual ~IPlugin(){} | |||
| virtual void init(FeiqWin* feiqWin) | |||
| { | |||
| mFeiq = feiqWin; | |||
| } | |||
| virtual void unInit() = 0; | |||
| protected: | |||
| FeiqWin* mFeiq; | |||
| }; | |||
| #endif // IPLUGIN_H | |||
| @@ -0,0 +1,34 @@ | |||
| #include "unreadchecker.h" | |||
| #include <QTimerEvent> | |||
| #include "platformdepend.h" | |||
| UnreadChecker::UnreadChecker() | |||
| { | |||
| } | |||
| void UnreadChecker::timerEvent(QTimerEvent *event) | |||
| { | |||
| if (event->timerId() == mUnreadTimerId) | |||
| { | |||
| auto count = mFeiq->getUnreadCount(); | |||
| if (count > 0) | |||
| PlatformDepend::instance().showNotify("未读提醒", QString("还有%1条未读消息").arg(count)); | |||
| } | |||
| } | |||
| void UnreadChecker::init(FeiqWin *feiqWin) | |||
| { | |||
| IPlugin::init(feiqWin); | |||
| auto settings = mFeiq->settings(); | |||
| mUnreadTimerInterval = settings->value("app/unread_timer", "0").toInt(); | |||
| if (mUnreadTimerInterval > 0) | |||
| mUnreadTimerId = startTimer(mUnreadTimerInterval*1000, Qt::VeryCoarseTimer); | |||
| } | |||
| void UnreadChecker::unInit() | |||
| { | |||
| if (mUnreadTimerId > 0) | |||
| killTimer(mUnreadTimerId); | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| #ifndef UNREADCHECKER_H | |||
| #define UNREADCHECKER_H | |||
| #include "iplugin.h" | |||
| #include <QObject> | |||
| class UnreadChecker : public QObject, public IPlugin | |||
| { | |||
| Q_OBJECT | |||
| public: | |||
| UnreadChecker(); | |||
| void init(FeiqWin* feiqWin) override; | |||
| void unInit() override; | |||
| protected: | |||
| void timerEvent(QTimerEvent *event) override; | |||
| private: | |||
| int mUnreadTimerInterval; | |||
| int mUnreadTimerId=-1; | |||
| }; | |||
| #endif // UNREADCHECKER_H | |||