qmlFrontend/hwengine.cpp
branchqmlfrontend
changeset 10444 47a6231f1fc1
parent 10442 c58db813240b
child 10448 4cb727e029fa
equal deleted inserted replaced
10442:c58db813240b 10444:47a6231f1fc1
    19     flibFree_t *flibFree;
    19     flibFree_t *flibFree;
    20     getThemesList_t *flibGetThemesList;
    20     getThemesList_t *flibGetThemesList;
    21     freeThemesList_t *flibFreeThemesList;
    21     freeThemesList_t *flibFreeThemesList;
    22     getThemeIcon_t *flibGetThemeIcon;
    22     getThemeIcon_t *flibGetThemeIcon;
    23     getTeamsList_t *flibGetTeamsList;
    23     getTeamsList_t *flibGetTeamsList;
       
    24     tryAddTeam_t * flibTryAddTeam;
       
    25     tryRemoveTeam_t * flibTryRemoveTeam;
    24 }
    26 }
    25 
    27 
    26 Q_DECLARE_METATYPE(MessageType);
    28 Q_DECLARE_METATYPE(MessageType);
    27 
    29 
    28 HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) :
    30 HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) :
    48     flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList");
    50     flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList");
    49     flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
    51     flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
    50     flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon");
    52     flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon");
    51 
    53 
    52     flibGetTeamsList = (getTeamsList_t*) hwlib.resolve("getTeamsList");
    54     flibGetTeamsList = (getTeamsList_t*) hwlib.resolve("getTeamsList");
       
    55     flibTryAddTeam = (tryAddTeam_t*) hwlib.resolve("tryAddTeam");
       
    56     flibTryRemoveTeam = (tryRemoveTeam_t*) hwlib.resolve("tryRemoveTeam");
    53 
    57 
    54     flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
    58     flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
    55     flibRegisterGUIMessagesCallback(this, &guiMessagesCallback);
    59     flibRegisterGUIMessagesCallback(this, &guiMessagesCallback);
    56 
    60 
    57     ThemeIconProvider * themeIcon = (ThemeIconProvider *)m_engine->imageProvider(QLatin1String("theme"));
    61     ThemeIconProvider * themeIcon = (ThemeIconProvider *)m_engine->imageProvider(QLatin1String("theme"));
    93 
    97 
    94 
    98 
    95 void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len)
    99 void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len)
    96 {
   100 {
    97     HWEngine * obj = (HWEngine *)context;
   101     HWEngine * obj = (HWEngine *)context;
    98     QByteArray b = QByteArray::fromRawData(msg, len);
   102     QByteArray b = QByteArray(msg, len);
    99 
   103 
   100     qDebug() << "FLIPC in" << b.size() << b;
   104     qDebug() << "FLIPC in" << b.size() << b;
   101 
   105 
   102     QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
   106     QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
   103 }
   107 }
   104 
   108 
   105 void HWEngine::engineMessageHandler(MessageType mt, const QByteArray &msg)
   109 void HWEngine::engineMessageHandler(MessageType mt, const QByteArray &msg)
   106 {
   110 {
   107     switch(mt)
   111     switch(mt)
   108     {
   112     {
   109     case MSG_PREVIEW:
   113     case MSG_PREVIEW: {
   110         PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
   114         PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
   111         preview->setPixmap(msg);
   115         preview->setPixmap(msg);
   112         emit previewImageChanged();
   116         emit previewImageChanged();
   113         break;
   117         break;
       
   118     }
       
   119     case MSG_ADDPLAYINGTEAM: {
       
   120         QStringList l = QString::fromUtf8(msg).split('\n');
       
   121         emit playingTeamAdded(l[1], l[0].toInt(), true);
       
   122         break;
       
   123     }
       
   124     case MSG_REMOVEPLAYINGTEAM: {
       
   125         emit playingTeamRemoved(msg);
       
   126         break;
       
   127     }
       
   128     case MSG_ADDTEAM: {
       
   129         emit localTeamAdded(msg, 0);
       
   130         break;
       
   131     }
       
   132     case MSG_REMOVETEAM: {
       
   133         emit localTeamRemoved(msg);
       
   134         break;
       
   135     }
   114     }
   136     }
   115 }
   137 }
   116 
   138 
   117 QString HWEngine::currentSeed()
   139 QString HWEngine::currentSeed()
   118 {
   140 {
   141         QString team = QString::fromUtf8(*i);
   163         QString team = QString::fromUtf8(*i);
   142 
   164 
   143         emit localTeamAdded(team, 0);
   165         emit localTeamAdded(team, 0);
   144     }
   166     }
   145 }
   167 }
       
   168 
       
   169 void HWEngine::tryAddTeam(const QString &teamName)
       
   170 {
       
   171     flibTryAddTeam(teamName.toUtf8().constData());
       
   172 }
       
   173 
       
   174 void HWEngine::tryRemoveTeam(const QString &teamName)
       
   175 {
       
   176     flibTryRemoveTeam(teamName.toUtf8().constData());
       
   177 }