Changeset 2959
- Timestamp:
- 04/27/06 18:36:36 (3 years ago)
- Files:
-
- hydranode/hncore/ed2k/serverlist.cpp (modified) (6 diffs)
- hydranode/hncore/ed2k/serverlist.h (modified) (2 diffs)
- hydranode/hngui/plugins/donkeypage.cpp (modified) (5 diffs)
- hydranode/hngui/plugins/donkeypage.h (modified) (2 diffs)
- hydranode/hngui/plugins/donkeypage_ui.ui (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/hncore/ed2k/serverlist.cpp
r2956 r2959 331 331 logMsg(boost::format("eDonkey2000: Connecting to %s") % addr); 332 332 m_status = ST_CONNECTING; 333 notify(); 333 334 } 334 335 … … 343 344 "sending login request." 344 345 ); 346 m_status = ST_LOGGINGIN; 347 notify(); 345 348 sendLoginRequest(); 346 349 break; … … 535 538 536 539 ED2K::instance().setId(p.getId()); 540 notify(); 537 541 m_currentServer->setTcpFlags(p.getFlags()); 538 542 539 543 if (m_status != ST_CONNECTED) { 540 544 m_status = ST_CONNECTED; 545 notify(); 541 546 logMsg( 542 547 "eDonkey2000: We are now connected " … … 1195 1200 uint32_t ServerList::getOperCount() const { 1196 1201 #ifndef NDEBUG 1197 return 5;1202 return 6; 1198 1203 #else 1199 return 4;1204 return 5; 1200 1205 #endif 1201 1206 } … … 1282 1287 } 1283 1288 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 } 1284 1302 } else if (op.getName() == "list") { 1285 1303 std::vector<Server*> tmp; … … 1323 1341 } 1324 1342 1343 uint32_t ServerList::getDataCount() const { return 3; } 1344 std::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 1353 std::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 1325 1376 void ServerList::doGlobSearch( 1326 1377 SearchPtr search, boost::shared_ptr<std::list<Server*> > srv hydranode/hncore/ed2k/serverlist.h
r2942 r2959 125 125 enum Status { 126 126 ST_CONNECTED = 0x01, //!< Connected 127 ST_CONNECTING = 0x02 //!< Not connected 127 ST_CONNECTING = 0x02, //!< Not connected 128 ST_LOGGINGIN = 0x03 //!< Logging in to server 128 129 }; 129 130 … … 311 312 virtual Object::Operation getOper(uint32_t n) const; 312 313 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; 313 317 //@} 314 318 }; hydranode/hngui/plugins/donkeypage.cpp
r2957 r2959 25 25 #include <QSettings> 26 26 #include <limits> 27 #include <QPainter> 28 29 // DonkeyStatusBar class 30 DonkeyStatusBar::DonkeyStatusBar(QWidget *parent) : QFrame(parent) {} 31 32 void 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 } 27 39 28 40 // ServerList class … … 115 127 // DonkeyPage class 116 128 DonkeyPage::DonkeyPage(QWidget *parent, Engine::Modules *p) 117 : QWidget(parent) {129 : QWidget(parent), m_currentServer() { 118 130 m_ui = new Ui::DonkeyPage; 119 131 m_ui->setupUi(this); … … 153 165 ++i; 154 166 } 167 m_serverList = obj; 155 168 m_ui->serverList->sortItems(3, Qt::DescendingOrder); 169 updateObject(m_serverList); 170 updateNetworkInfo(); 156 171 } 157 172 158 173 void 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 159 218 QMap<quint32, ServerListItem*>::iterator it =m_list.find(obj->getId()); 160 219 if (it != m_list.end()) { … … 170 229 m_ui->serverList->header()->sortIndicatorOrder() 171 230 ); 231 updateNetworkInfo(); 172 232 } 173 233 … … 197 257 if (it != m_list.end()) { 198 258 logDebug(" -> removing [del-real]"); 259 if (m_currentServer == it.value()) { 260 m_currentServer = 0; 261 } 199 262 delete it.value(); 200 263 m_list.erase(it); 201 264 } 202 265 } 266 267 QString 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 279 void 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 38 38 }; 39 39 40 class DonkeyStatusBar : public QFrame { 41 public: 42 DonkeyStatusBar(QWidget *parent); 43 protected: 44 void paintEvent(QPaintEvent *evt); 45 }; 46 40 47 class ServerListItem : public QTreeWidgetItem { 41 48 public: … … 54 61 void delObject(Engine::ObjectPtr obj); 55 62 63 QString formatNumber(quint32 n); 64 void updateNetworkInfo(); 65 56 66 Ui::DonkeyPage *m_ui; 57 67 Engine::Modules *m_modules; 58 68 QMap<quint32, ServerListItem*> m_list; 69 Engine::ObjectPtr m_serverList; 70 ServerListItem *m_currentServer; 59 71 }; 60 72 hydranode/hngui/plugins/donkeypage_ui.ui
r2948 r2959 10 10 <y>0</y> 11 11 <width>515</width> 12 <height> 351</height>12 <height>428</height> 13 13 </rect> 14 14 </property> … … 21 21 </property> 22 22 <property name="spacing" > 23 <number> 6</number>23 <number>0</number> 24 24 </property> 25 25 <item row="0" column="0" > … … 45 45 </widget> 46 46 </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><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Files:</span></p></body></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> 47 164 </layout> 48 165 </widget> … … 56 173 <pixmap></pixmap> 57 174 </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> 58 182 </customwidgets> 59 183 <resources/>
