Changeset 2959

Show
Ignore:
Timestamp:
04/27/06 18:36:36 (3 years ago)
Author:
madcat
Message:

Now displays ed2k server status on the gui ed2k page.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/hncore/ed2k/serverlist.cpp

    r2956 r2959  
    331331        logMsg(boost::format("eDonkey2000: Connecting to %s") % addr); 
    332332        m_status = ST_CONNECTING; 
     333        notify(); 
    333334} 
    334335 
     
    343344                                "sending login request." 
    344345                        ); 
     346                        m_status = ST_LOGGINGIN; 
     347                        notify(); 
    345348                        sendLoginRequest(); 
    346349                        break; 
     
    535538 
    536539        ED2K::instance().setId(p.getId()); 
     540        notify(); 
    537541        m_currentServer->setTcpFlags(p.getFlags()); 
    538542 
    539543        if (m_status != ST_CONNECTED) { 
    540544                m_status = ST_CONNECTED; 
     545                notify(); 
    541546                logMsg( 
    542547                        "eDonkey2000: We are now connected " 
     
    11951200uint32_t ServerList::getOperCount() const {  
    11961201#ifndef NDEBUG 
    1197         return 5;  
     1202        return 6;  
    11981203#else 
    1199         return 4
     1204        return 5
    12001205#endif 
    12011206} 
     
    12821287                } 
    12831288                return; 
     1289        } else if (op.getName() == "connectId") { 
     1290                uint32_t id = boost::lexical_cast<uint32_t>( 
     1291                        op.getArg("id").getValue() 
     1292                ); 
     1293                if (id) { 
     1294                        Object *obj = findChild(id); 
     1295                        if (obj) { 
     1296                                Server *s = dynamic_cast<Server*>(obj); 
     1297                                if (s) { 
     1298                                        connect(s); 
     1299                                } 
     1300                        } 
     1301                } 
    12841302        } else if (op.getName() == "list") { 
    12851303                std::vector<Server*> tmp; 
     
    13231341} 
    13241342 
     1343uint32_t ServerList::getDataCount() const { return 3; } 
     1344std::string ServerList::getFieldName(uint32_t n) const { 
     1345        switch (n) { 
     1346                case 0:  return "Status"; 
     1347                case 1:  return "CurrentServerId"; 
     1348                case 2:  return "ClientId"; 
     1349                default: return ""; 
     1350        } 
     1351} 
     1352 
     1353std::string ServerList::getData(uint32_t n) const { 
     1354        switch (n) { 
     1355                case 0: if (m_status == ST_CONNECTING) { 
     1356                                return "Connecting"; 
     1357                        } else if (m_status == ST_LOGGINGIN) { 
     1358                                return "Logging in "; 
     1359                        } else { 
     1360                                return "Connected"; 
     1361                        } 
     1362                case 1: if (m_currentServer) { 
     1363                                return boost::lexical_cast<std::string>( 
     1364                                        m_currentServer->getId() 
     1365                                ); 
     1366                        } else { 
     1367                                return "0"; 
     1368                        } 
     1369                case 2: return boost::lexical_cast<std::string>( 
     1370                                ED2K::instance().getId() 
     1371                        ); 
     1372                default: return ""; 
     1373        } 
     1374} 
     1375 
    13251376void ServerList::doGlobSearch( 
    13261377        SearchPtr search, boost::shared_ptr<std::list<Server*> > srv 
  • hydranode/hncore/ed2k/serverlist.h

    r2942 r2959  
    125125        enum Status { 
    126126                ST_CONNECTED  = 0x01,       //!< Connected 
    127                 ST_CONNECTING = 0x02        //!< Not connected 
     127                ST_CONNECTING = 0x02,       //!< Not connected 
     128                ST_LOGGINGIN  = 0x03        //!< Logging in to server 
    128129        }; 
    129130 
     
    311312        virtual Object::Operation getOper(uint32_t n) const; 
    312313        virtual void doOper(const Object::Operation &op); 
     314        virtual uint32_t getDataCount() const; 
     315        virtual std::string getData(uint32_t n) const; 
     316        virtual std::string getFieldName(uint32_t n) const; 
    313317        //@} 
    314318}; 
  • hydranode/hngui/plugins/donkeypage.cpp

    r2957 r2959  
    2525#include <QSettings> 
    2626#include <limits> 
     27#include <QPainter> 
     28 
     29// DonkeyStatusBar class 
     30DonkeyStatusBar::DonkeyStatusBar(QWidget *parent) : QFrame(parent) {} 
     31 
     32void DonkeyStatusBar::paintEvent(QPaintEvent *evt) { 
     33        QFrame::paintEvent(evt); 
     34        QPainter p(this); 
     35        p.setPen(Qt::white); 
     36        p.setBrush(Qt::white); 
     37        p.drawRect(0, 0, width(), height()); 
     38} 
    2739 
    2840// ServerList class 
     
    115127// DonkeyPage class 
    116128DonkeyPage::DonkeyPage(QWidget *parent, Engine::Modules *p)  
    117 : QWidget(parent)
     129: QWidget(parent), m_currentServer()
    118130        m_ui = new Ui::DonkeyPage; 
    119131        m_ui->setupUi(this); 
     
    153165                ++i; 
    154166        } 
     167        m_serverList = obj; 
    155168        m_ui->serverList->sortItems(3, Qt::DescendingOrder); 
     169        updateObject(m_serverList); 
     170        updateNetworkInfo(); 
    156171} 
    157172 
    158173void DonkeyPage::updateObject(Engine::ObjectPtr obj) { 
     174        if (obj == m_serverList) { 
     175                QString status = QString::fromStdString(obj->getData(0)); 
     176                QString curServer = QString::fromStdString(obj->getData(1)); 
     177                QString id = QString::fromStdString(obj->getData(2)); 
     178                ServerListItem *cur = m_list.value(curServer.toUInt()); 
     179                if (cur && m_currentServer) { 
     180                        for (int i = 0; i < m_currentServer->columnCount();++i){ 
     181                                QFont f(m_currentServer->font(i)); 
     182                                f.setBold(false); 
     183                                m_currentServer->setFont(i, f); 
     184                        } 
     185                } 
     186                if (cur) { 
     187                        for (int i = 0; i < cur->columnCount(); ++i) { 
     188                                QFont f(cur->font(i)); 
     189                                f.setBold(true); 
     190                                cur->setFont(i, f); 
     191                        } 
     192                        m_currentServer = cur; 
     193                        QString statusText(status + " to " + cur->text(0)); 
     194                        statusText += " (" +formatNumber(cur->text(3).toUInt()); 
     195                        statusText += " users and "; 
     196                        statusText += formatNumber(cur->text(4).toUInt()); 
     197                        statusText += " files)"; 
     198                        if (status != "Connecting") { 
     199                                statusText += " with "; 
     200                                if (id.toUInt() <= 0x00ffffff) { 
     201                                        statusText += "Low Id"; 
     202                                } else { 
     203                                        statusText += "High Id"; 
     204                                } 
     205                        } 
     206                        m_ui->statusText->setText(statusText); 
     207                } else { 
     208                        logDebug("Status: " + status); 
     209                        logDebug("CurServer: " + curServer); 
     210                        logDebug("ID: " + id); 
     211                        m_ui->statusText->setText( 
     212                                "No status information available." 
     213                        ); 
     214                } 
     215                return; 
     216        } 
     217 
    159218        QMap<quint32, ServerListItem*>::iterator it =m_list.find(obj->getId()); 
    160219        if (it != m_list.end()) { 
     
    170229                m_ui->serverList->header()->sortIndicatorOrder() 
    171230        ); 
     231        updateNetworkInfo(); 
    172232} 
    173233 
     
    197257        if (it != m_list.end()) { 
    198258                logDebug(" -> removing [del-real]"); 
     259                if (m_currentServer == it.value()) { 
     260                        m_currentServer = 0; 
     261                } 
    199262                delete it.value(); 
    200263                m_list.erase(it); 
    201264        } 
    202265} 
     266 
     267QString DonkeyPage::formatNumber(quint32 n) { 
     268        QString num(QString::number(n)); 
     269        int c = 0; 
     270        for (int i = num.size() - 1; i >= 0; --i) { 
     271                if (++c == 3 && i) { 
     272                        num.insert(i, "'"); 
     273                        c = 0; 
     274                } 
     275        } 
     276        return num; 
     277} 
     278 
     279void DonkeyPage::updateNetworkInfo() { 
     280        quint32 users = 0; 
     281        quint32 files = 0; 
     282        Q_FOREACH(ServerListItem *it, m_list.values()) { 
     283                users += it->text(3).toUInt(); 
     284                files += it->text(4).toUInt(); 
     285        } 
     286        m_ui->userCount->setText("Users: " + formatNumber(users)); 
     287        m_ui->fileCount->setText("Files: " + formatNumber(files)); 
     288} 
  • hydranode/hngui/plugins/donkeypage.h

    r2957 r2959  
    3838}; 
    3939 
     40class DonkeyStatusBar : public QFrame { 
     41public: 
     42        DonkeyStatusBar(QWidget *parent); 
     43protected: 
     44        void paintEvent(QPaintEvent *evt); 
     45}; 
     46 
    4047class ServerListItem : public QTreeWidgetItem { 
    4148public: 
     
    5461        void delObject(Engine::ObjectPtr obj); 
    5562 
     63        QString formatNumber(quint32 n); 
     64        void updateNetworkInfo(); 
     65 
    5666        Ui::DonkeyPage  *m_ui; 
    5767        Engine::Modules *m_modules; 
    5868        QMap<quint32, ServerListItem*> m_list; 
     69        Engine::ObjectPtr m_serverList; 
     70        ServerListItem *m_currentServer; 
    5971}; 
    6072 
  • hydranode/hngui/plugins/donkeypage_ui.ui

    r2948 r2959  
    1010    <y>0</y> 
    1111    <width>515</width> 
    12     <height>351</height> 
     12    <height>428</height> 
    1313   </rect> 
    1414  </property> 
     
    2121   </property> 
    2222   <property name="spacing" > 
    23     <number>6</number> 
     23    <number>0</number> 
    2424   </property> 
    2525   <item row="0" column="0" > 
     
    4545    </widget> 
    4646   </item> 
     47   <item row="1" column="0" > 
     48    <widget class="DonkeyStatusBar" name="statusBar" > 
     49     <property name="maximumSize" > 
     50      <size> 
     51       <width>16777215</width> 
     52       <height>18</height> 
     53      </size> 
     54     </property> 
     55     <property name="frameShape" > 
     56      <enum>QFrame::StyledPanel</enum> 
     57     </property> 
     58     <property name="frameShadow" > 
     59      <enum>QFrame::Raised</enum> 
     60     </property> 
     61     <layout class="QGridLayout" > 
     62      <property name="margin" > 
     63       <number>0</number> 
     64      </property> 
     65      <property name="spacing" > 
     66       <number>0</number> 
     67      </property> 
     68      <item row="0" column="6" > 
     69       <spacer> 
     70        <property name="orientation" > 
     71         <enum>Qt::Horizontal</enum> 
     72        </property> 
     73        <property name="sizeType" > 
     74         <enum>QSizePolicy::Fixed</enum> 
     75        </property> 
     76        <property name="sizeHint" > 
     77         <size> 
     78          <width>5</width> 
     79          <height>20</height> 
     80         </size> 
     81        </property> 
     82       </spacer> 
     83      </item> 
     84      <item row="0" column="5" > 
     85       <widget class="QLabel" name="fileCount" > 
     86        <property name="text" > 
     87         <string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-size:8pt;">Files:&lt;/span>&lt;/p>&lt;/body>&lt;/html></string> 
     88        </property> 
     89       </widget> 
     90      </item> 
     91      <item row="0" column="4" > 
     92       <spacer> 
     93        <property name="orientation" > 
     94         <enum>Qt::Horizontal</enum> 
     95        </property> 
     96        <property name="sizeType" > 
     97         <enum>QSizePolicy::Fixed</enum> 
     98        </property> 
     99        <property name="sizeHint" > 
     100         <size> 
     101          <width>5</width> 
     102          <height>20</height> 
     103         </size> 
     104        </property> 
     105       </spacer> 
     106      </item> 
     107      <item row="0" column="3" > 
     108       <widget class="QLabel" name="userCount" > 
     109        <property name="text" > 
     110         <string>Users:</string> 
     111        </property> 
     112       </widget> 
     113      </item> 
     114      <item row="0" column="2" > 
     115       <spacer> 
     116        <property name="orientation" > 
     117         <enum>Qt::Horizontal</enum> 
     118        </property> 
     119        <property name="sizeType" > 
     120         <enum>QSizePolicy::Fixed</enum> 
     121        </property> 
     122        <property name="sizeHint" > 
     123         <size> 
     124          <width>5</width> 
     125          <height>20</height> 
     126         </size> 
     127        </property> 
     128       </spacer> 
     129      </item> 
     130      <item row="0" column="1" > 
     131       <widget class="QLabel" name="statusText" > 
     132        <property name="sizePolicy" > 
     133         <sizepolicy> 
     134          <hsizetype>5</hsizetype> 
     135          <vsizetype>5</vsizetype> 
     136          <horstretch>1</horstretch> 
     137          <verstretch>0</verstretch> 
     138         </sizepolicy> 
     139        </property> 
     140        <property name="text" > 
     141         <string>No status information available.</string> 
     142        </property> 
     143       </widget> 
     144      </item> 
     145      <item row="0" column="0" > 
     146       <spacer> 
     147        <property name="orientation" > 
     148         <enum>Qt::Horizontal</enum> 
     149        </property> 
     150        <property name="sizeType" > 
     151         <enum>QSizePolicy::Fixed</enum> 
     152        </property> 
     153        <property name="sizeHint" > 
     154         <size> 
     155          <width>5</width> 
     156          <height>16</height> 
     157         </size> 
     158        </property> 
     159       </spacer> 
     160      </item> 
     161     </layout> 
     162    </widget> 
     163   </item> 
    47164  </layout> 
    48165 </widget> 
     
    56173   <pixmap></pixmap> 
    57174  </customwidget> 
     175  <customwidget> 
     176   <class>DonkeyStatusBar</class> 
     177   <extends>QFrame</extends> 
     178   <header>plugins/donkeypage.h</header> 
     179   <container>0</container> 
     180   <pixmap></pixmap> 
     181  </customwidget> 
    58182 </customwidgets> 
    59183 <resources/>