- Timestamp:
- 12/24/08 18:40:39 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/HaliteListView.cpp
r651 r654 127 127 { 128 128 129 tD.sort(hal::torrent_details::peers_e); 130 131 if (IsGroupViewEnabled()) 132 tD.sort(hal::torrent_details::managed_e); 133 129 134 # if 0 130 135 if (GetItemCount() > 0) … … 148 153 # endif 149 154 150 for each (const hal::torrent_details_ptr td, tD.torrents())151 { 152 153 LV_FINDINFO findInfo;155 for (size_t td_index=0, e=tD.torrents().size(); td_index<e; ++td_index) 156 { 157 hal::torrent_details_ptr td = tD.torrents()[td_index]; 158 /*LV_FINDINFO findInfo; 154 159 findInfo.flags = LVFI_STRING; 155 160 findInfo.psz = const_cast<LPTSTR>(td->name().c_str()); 156 161 157 162 int itemPos = FindItem(&findInfo, -1); 158 if (itemPos < 0) 159 { 160 LVITEM lvItem = { 0 }; 161 lvItem.mask = LVIF_TEXT; 162 lvItem.iItem = 0; 163 lvItem.iSubItem = 0; 164 lvItem.pszText = (LPTSTR)td->name().c_str(); 165 166 if (IsGroupViewEnabled()) 167 { 168 lvItem.mask |= LVIF_GROUPID|LVIF_COLUMNS; 169 170 if (td->managed()) 171 lvItem.iGroupId = HAL_AUTO_MANAGED; 172 else 173 lvItem.iGroupId = HAL_UNMANAGED; 174 } 175 176 lvItem.mask |= LVIF_IMAGE; 177 lvItem.iImage = 0; 178 179 itemPos = InsertItem(&lvItem); 180 } 181 163 */ 164 165 LVITEM lvItem = { 0 }; 166 lvItem.mask = LVIF_TEXT; 167 lvItem.iSubItem = 0; 168 lvItem.pszText = (LPTSTR)td->name().c_str(); 169 170 if (IsGroupViewEnabled()) 171 { 172 lvItem.mask |= LVIF_GROUPID|LVIF_COLUMNS; 173 174 if (td->managed()) 175 lvItem.iGroupId = HAL_AUTO_MANAGED; 176 else 177 lvItem.iGroupId = HAL_UNMANAGED; 178 } 179 180 lvItem.mask |= LVIF_IMAGE; 181 lvItem.iImage = 0; 182 183 if (GetItemCount() <= static_cast<int>(td_index)) 184 { 185 lvItem.iItem = GetItemCount(); 186 td_index = InsertItem(&lvItem); 187 } 188 else 189 { 190 lvItem.iItem = td_index; 191 SetItem(&lvItem); 192 } 193 182 194 for (size_t i=1; i<NumberOfColumns_s; ++i) 183 195 { 184 SetItemText( itemPos, i, getColumnAdapter(i)->print(td).c_str());196 SetItemText(td_index, i, td->to_wstring(i).c_str()); 185 197 } 186 198 } … … 191 203 */ 192 204 } 205 } 206 207 void HaliteListViewCtrl::SortByColumn(size_t column_index) 208 { 209 //std::sort(data_elements_.begin(), data_elements_.end(), 210 // ); 211 193 212 } 194 213 -
trunk/src/HaliteListView.hpp
r651 r654 442 442 ar & make_nvp("queue_view", queue_view_); 443 443 } 444 444 445 void SortByColumn(size_t column_index); 446 445 447 /* tD CustomItemConversion(LVCompareParam* param, int iSortCol); 446 448 … … 460 462 461 463 enum { NumberOfColumns_s = 23 }; 464 465 std::vector<const hal::torrent_details_ptr> data_elements_; 462 466 463 467 HaliteWindow& halWindow_; -
trunk/src/HaliteSortListViewCtrl.hpp
r651 r654 59 59 { 60 60 public: 61 enum { COL_MENU_NAMES = 123, COL_MAX_NAMES = 256 };61 enum { COL_MENU_NAMES = 123, COL_MAX_NAMES = 256 }; 62 62 63 63 CHaliteHeaderCtrl(thisClass& listView) : … … 98 98 minfo.fState = visible ? MFS_CHECKED : MFS_UNCHECKED; 99 99 100 menu_.SetMenuItemInfo(wID, false, &minfo); */101 100 menu_.SetMenuItemInfo(wID, false, &minfo); 101 */ 102 102 return 0; 103 103 } … … 425 425 } 426 426 427 void SortByColumn(size_t column_index) 428 { 429 /* Overwriteable */ 430 } 431 427 432 int AddColumn(LPCTSTR strItem, int nItem, bool visible, int width=-1) 428 433 { … … 436 441 int nFmt = LVCFMT_LEFT, bool visible=true, int width=-1) 437 442 { 438 439 443 int i = parentClass::AddColumn(strItem, nItem, nSubItem, nMask, nFmt); 440 444 -
trunk/src/halTorrent.cpp
r648 r654 61 61 } 62 62 63 void torrent_details_manager::sort( 64 boost::function<bool (const torrent_details_ptr&, const torrent_details_ptr&)> fn) const 65 { 66 std::stable_sort(torrents_.begin(), torrents_.end(), fn); 63 bool torrent_details::less(const torrent_details& r, size_t index) 64 { 65 switch (index) 66 { 67 case name_e: return name_ < r.name_; 68 case state_e: return state_ < r.state_; 69 70 case speed_down_e: return speed_.first < r.speed_.first; 71 case speed_up_e: return speed_.second < r.speed_.second; 72 case progress_e: return completion_ < r.completion_; 73 case distributed_copies_e: return distributed_copies_ < r.distributed_copies_; 74 75 case remaining_e: 76 { 77 boost::int64_t left = totalWanted_-totalWantedDone_; 78 boost::int64_t right = r.totalWanted_-r.totalWantedDone_; 79 80 return left < right; 81 } 82 83 case total_wanted_e: return totalWanted_ < r.totalWanted_; 84 case completed_e: return totalWantedDone_ < r.totalWantedDone_; 85 86 case uploaded_e: return totalUploaded_ < r.totalUploaded_; 87 case downloaded_e: return totalPayloadUploaded_ < r.totalPayloadUploaded_; 88 89 case peers_e: return peers_ < r.peers_; 90 case seeds_e: return seeds_ < r.seeds_; 91 92 case ratio_e: 93 { 94 float left = (totalPayloadDownloaded_) 95 ? static_cast<float>(totalPayloadUploaded_) 96 / static_cast<float>(totalPayloadDownloaded_) 97 : 0; 98 99 float right = (r.totalPayloadDownloaded_) 100 ? static_cast<float>(r.totalPayloadUploaded_) 101 / static_cast<float>(r.totalPayloadDownloaded_) 102 : 0; 103 104 return left < right; 105 } 106 107 case eta_e: return estimatedTimeLeft_ < r.estimatedTimeLeft_; 108 case tracker: return currentTracker_ < r.currentTracker_; 109 case update_tracker_in_e: return updateTrackerIn_ < r.updateTrackerIn_; 110 111 case active_time_e: return active_ < r.active_; 112 case seeding_time_e: return seeding_ < r.seeding_; 113 case start_time_e: return startTime_ < r.startTime_; 114 case finish_time_e: return finishTime_ < r.finishTime_; 115 116 case queue_position_e: return queue_position_ < r.queue_position_; 117 case managed_e: return managed_ < r.managed_; 118 119 default: return false; // ??? 120 }; 121 } 122 123 std::wstring torrent_details::to_wstring(size_t index) 124 { 125 switch (index) 126 { 127 case name_e: return name_; 128 case state_e: return state_; 129 130 case progress_e: return (wform(L"%1$.2f%%") % (completion_*100)).str(); 131 case speed_down_e: return (wform(L"%1$.2fkb/s") % (speed_.first/1024)).str(); 132 case speed_up_e: return (wform(L"%1$.2fkb/s") % (speed_.second/1024)).str(); 133 134 case distributed_copies_e: 135 { 136 float copies = distributed_copies_; 137 138 if (copies < 0) 139 return L"Seeding"; 140 else 141 return (hal::wform(L"%1$.2f") % copies).str(); 142 } 143 144 case remaining_e: 145 { 146 return (wform(L"%1$.2fMB") % (static_cast<float>(totalWanted_-totalWantedDone_)/(1024*1024))).str(); 147 } 148 149 case completed_e: return (wform(L"%1$.2fMB") % (static_cast<float>(totalWantedDone_)/(1024*1024))).str(); 150 151 case total_wanted_e: 152 { 153 return (wform(L"%1$.2fMB") % (static_cast<float>(totalWanted_-totalWantedDone_)/(1024*1024))).str(); 154 } 155 156 case uploaded_e: 157 { 158 return (wform(L"%1$.2fMB") % (static_cast<float>(totalPayloadUploaded_)/(1024*1024))).str(); 159 } 160 161 case downloaded_e: 162 { 163 return (wform(L"%1$.2fMB") % (static_cast<float>(totalPayloadDownloaded_)/(1024*1024))).str(); 164 } 165 166 case peers_e: return (wform(L"%1% (%2%)") % connectedPeers_ % peers_).str(); 167 case seeds_e: return (wform(L"%1% (%2%)") % connectedSeeds_ % seeds_).str(); 168 169 case ratio_e: 170 { 171 float ratio = (totalPayloadDownloaded_) 172 ? static_cast<float>(totalPayloadUploaded_) 173 / static_cast<float>(totalPayloadDownloaded_) 174 : 0; 175 176 return (wform(L"%1$.2f") % ratio).str(); 177 } 178 179 case eta_e: 180 { 181 if (!estimatedTimeLeft_.is_special()) 182 return hal::from_utf8( 183 boost::posix_time::to_simple_string(estimatedTimeLeft_)); 184 else 185 return app().res_wstr(HAL_INF); 186 } 187 188 case tracker: return currentTracker_; 189 190 case update_tracker_in_e: 191 { 192 if (!updateTrackerIn_.is_special()) 193 return from_utf8( 194 boost::posix_time::to_simple_string(updateTrackerIn_)); 195 else 196 return app().res_wstr(HAL_INF); 197 } 198 199 case active_time_e: 200 { 201 if (!active_.is_special()) 202 return from_utf8( 203 boost::posix_time::to_simple_string(active_)); 204 else 205 return app().res_wstr(HAL_INF); 206 } 207 208 case seeding_time_e: 209 { 210 if (!seeding_.is_special()) 211 return from_utf8( 212 boost::posix_time::to_simple_string(seeding_)); 213 else 214 return app().res_wstr(HAL_INF); 215 } 216 217 case start_time_e: 218 { 219 if (!startTime_.is_special()) 220 return from_utf8( 221 boost::posix_time::to_simple_string(startTime_)); 222 else 223 return app().res_wstr(IDS_NA); 224 } 225 226 case finish_time_e: 227 { 228 if (!finishTime_.is_special()) 229 return from_utf8( 230 boost::posix_time::to_simple_string(finishTime_)); 231 else 232 return app().res_wstr(IDS_NA); 233 } 234 235 case queue_position_e: 236 { 237 if (queue_position_ != -1) 238 return (wform(L"%1%") % queue_position_).str(); 239 else 240 return app().res_wstr(IDS_NA); 241 } 242 243 case managed_e: 244 { 245 if (managed_) 246 return L"Yes"; 247 else 248 return L"No"; 249 } 250 251 default: return L"(Undefined)"; // ??? 252 }; 253 } 254 255 template<typename torrent_Tptr> 256 bool torrent_details_less(torrent_Tptr l, torrent_Tptr r, size_t index = 0) 257 { 258 return l->less(*r, index); 259 } 260 261 void torrent_details_manager::sort(size_t column_index) const 262 { 263 std::stable_sort(torrents_.begin(), torrents_.end(), 264 bind(&torrent_details_less<torrent_details_ptr>, _1, _2, column_index)); 67 265 } 68 266 -
trunk/src/halTorrent.hpp
r648 r654 393 393 std::wstring cT, 394 394 std::pair<float,float> sp=std::pair<float,float>(0,0), 395 float c=0, 395 float c=0, float d=0, 396 396 size_type tWD=0, size_type tW=0, 397 397 size_type tU=0, size_type tpU=0, … … 452 452 torrent_stopping 453 453 }; 454 455 enum details 456 { 457 name_e = 0, 458 state_e, 459 progress_e, 460 speed_down_e, 461 speed_up_e, 462 peers_e, 463 seeds_e, 464 eta_e, 465 distributed_copies_e, 466 tracker, 467 update_tracker_in_e, 468 ratio_e, 469 total_wanted_e, 470 completed_e, 471 remaining_e, 472 downloaded_e, 473 uploaded_e, 474 active_time_e, 475 seeding_time_e, 476 start_time_e, 477 finish_time_e, 478 managed_e, 479 queue_position_e 480 }; 481 454 482 455 483 // const std::wstring& filename() const { return filename_; } … … 490 518 int queue_position() const { return queue_position_; } 491 519 bool managed() const { return managed_; } 520 521 bool less(const torrent_details& r, size_t index = 0); 522 std::wstring to_wstring(size_t index = 0); 492 523 493 524 public: … … 544 575 { 545 576 public: 546 void sort( boost::function<bool (const torrent_details_ptr&, const torrent_details_ptr&)> fn) const;577 void sort(size_t index) const; 547 578 548 579 const torrent_details_vec torrents() const … … 581 612 void clearAll(const mutex_t::scoped_lock&) 582 613 { 583 // !! No mutex lock, it should only be call from functions which614 // !! No mutex lock, it should only be called from functions which 584 615 // have the lock themselves, hence the unused function param 585 616
Note: See TracChangeset
for help on using the changeset viewer.