void ManagedFileListWidget::Download() { #ifdef HAVE_DOWNLOAD_MANAGER assert(Net::DownloadManager::IsAvailable()); if (items.empty()) return; const unsigned current = GetList().GetCursorIndex(); assert(current < items.size()); const FileItem &item = items[current]; const AvailableFile *remote_file_p = FindRemoteFile(repository, item.name); if (remote_file_p == NULL) return; const AvailableFile &remote_file = *remote_file_p; ACPToWideConverter base(remote_file.GetName()); if (!base.IsValid()) return; Net::DownloadManager::Enqueue(remote_file.uri.c_str(), base); #endif }
void Expire(fixed clock) { new_traffic.Expire(clock, fixed(60)); for (unsigned i = list.size(); i-- > 0;) if (!list[i].Refresh(clock)) list.quick_remove(i); }
void ManagedFileListWidget::RefreshList() { items.clear(); bool download_active = false; for (auto i = repository.begin(), end = repository.end(); i != end; ++i) { const auto &remote_file = *i; DownloadStatus download_status; const bool is_downloading = IsDownloading(remote_file, download_status); TCHAR path[MAX_PATH]; if (LocalPath(path, remote_file) && (is_downloading || File::Exists(path))) { download_active |= is_downloading; items.append().Set(BaseName(path), is_downloading ? &download_status : NULL, HasFailed(remote_file)); } } ListControl &list = GetList(); list.SetLength(items.size()); list.Invalidate(); #ifdef HAVE_DOWNLOAD_MANAGER if (download_active && !Timer::IsActive()) Timer::Schedule(1000); #endif }
static void SetFormDefaultFocus() { unsigned numColumns = grid_view->GetNumColumns(); unsigned pageSize = numColumns * grid_view->GetNumRows(); unsigned lastPage = buttons.size() / pageSize; unsigned currentPage = grid_view->GetCurrentPage(); unsigned currentPageSize = currentPage == lastPage ? buttons.size() % pageSize : pageSize; unsigned centerCol = currentPageSize < numColumns ? currentPageSize / 2 : numColumns / 2; unsigned centerRow = currentPageSize / numColumns / 2; unsigned centerPos = currentPage * pageSize + centerCol + centerRow * numColumns; if (centerPos < buttons.size()) { if (wf->is_visible()) { buttons[centerPos]->set_focus(); grid_view->RefreshLayout(); } else if (buttons[centerPos]->is_enabled()) wf->SetDefaultFocus(buttons[centerPos]); } }
void ManagedFileListWidget::RefreshList() { items.clear(); bool download_active = false; for (auto i = repository.begin(), end = repository.end(); i != end; ++i) { const auto &remote_file = *i; DownloadStatus download_status; const bool is_downloading = IsDownloading(remote_file, download_status); const auto path = LocalPath(remote_file); if (!path.IsNull() && (is_downloading || File::Exists(path))) { download_active |= is_downloading; const Path base = path.GetBase(); if (base.IsNull()) continue; items.append().Set(base.c_str(), is_downloading ? &download_status : nullptr, HasFailed(remote_file)); } } ListControl &list = GetList(); list.SetLength(items.size()); list.Invalidate(); #ifdef HAVE_DOWNLOAD_MANAGER if (download_active && !Timer::IsActive()) Timer::Schedule(1000); #endif }
int AppendMode(const TCHAR *name) { if (modes.full()) return -1; modes.append() = name; return modes.size() - 1; }
int ManagedFileListWidget::FindItem(const TCHAR *name) const { for (auto i = items.begin(), end = items.end(); i != end; ++i) if (StringIsEqual(i->name, name)) return std::distance(items.begin(), i); return -1; }
inline void WifiListWidget::UpdateScanResults() { WifiVisibleNetwork *buffer = new WifiVisibleNetwork[networks.capacity()]; int n = wpa_supplicant.ScanResults(buffer, networks.capacity()); if (n >= 0) MergeList(buffer, n); delete[] buffer; }
inline void WifiListWidget::UpdateConfigured() { WifiConfiguredNetworkInfo *buffer = new WifiConfiguredNetworkInfo[networks.capacity()]; int n = wpa_supplicant.ListNetworks(buffer, networks.capacity()); if (n >= 0) MergeList(buffer, n); delete[] buffer; }
unsigned AppendEvent(pt2Event handler, const TCHAR *misc, unsigned next) { if (events.full()) return 0; Event &event = events.append(); event.event = handler; event.misc = misc; event.next = next; return events.size() - 1; }
WifiListWidget::NetworkInfo * WifiListWidget::FindVisibleBySSID(const char *ssid) { auto f = std::find_if(networks.begin(), networks.end(), [ssid](const NetworkInfo &info) { return info.signal_level >= 0 && info.ssid == ssid; }); if (f == networks.end()) return nullptr; return f; }
WifiListWidget::NetworkInfo * WifiListWidget::FindByBSSID(const char *bssid) { auto f = std::find_if(networks.begin(), networks.end(), [bssid](const NetworkInfo &info) { return info.bssid == bssid; }); if (f == networks.end()) return nullptr; return f; }
inline WifiListWidget::NetworkInfo * WifiListWidget::FindByID(int id) { auto f = std::find_if(networks.begin(), networks.end(), [id](const NetworkInfo &info) { return info.id == id; }); if (f == networks.end()) return nullptr; return f; }
void ManagedFileListWidget::UpdateButtons() { #ifdef HAVE_DOWNLOAD_MANAGER if (Net::DownloadManager::IsAvailable()) { const unsigned current = GetList().GetCursorIndex(); download_button->SetEnabled(!items.empty() && CanDownload(repository, items[current].name)); cancel_button->SetEnabled(!items.empty() && items[current].downloading); } #endif }
void ManagedFileListWidget::Cancel() { #ifdef HAVE_DOWNLOAD_MANAGER assert(Net::DownloadManager::IsAvailable()); if (items.empty()) return; const unsigned current = GetList().GetCursorIndex(); assert(current < items.size()); const FileItem &item = items[current]; Net::DownloadManager::Cancel(item.name); #endif }
void NOAAListWidget::OpenDetails(unsigned index) { assert(index < stations.size()); dlgNOAADetailsShowModal(stations[index].iterator); UpdateList(); }
inline void WifiListWidget::Connect() { if (!EnsureConnected()) { ShowMessageBox(_T("Network failure"), _("Connect"), MB_OK); return; } const unsigned i = GetList().GetCursorIndex(); if (i >= networks.size()) return; const auto &info = networks[i]; if (info.id < 0) { const auto ssid = info.ssid; StaticString<256> caption; caption.Format(_("Passphrase of network '%s'"), ssid.c_str()); StaticString<32> passphrase; passphrase.clear(); if (info.security == OPEN_SECURITY) passphrase.clear(); else if (!TextEntryDialog(passphrase, caption, false)) return; if (!WifiConnect(info.security, wpa_supplicant, info.ssid, passphrase)) ShowMessageBox(_T("Network failure"), _("Connect"), MB_OK); } else { if (!wpa_supplicant.RemoveNetwork(info.id) || !wpa_supplicant.SaveConfig()) ShowMessageBox(_T("Error"), _("Remove"), MB_OK); } UpdateList(); }
void NOAAListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc, unsigned index) { assert(index < stations.size()); NOAAListRenderer::Draw(canvas, rc, *stations[index].iterator, UIGlobals::GetDialogLook()); }
void NOAAListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc, unsigned index) { assert(index < stations.size()); NOAAListRenderer::Draw(canvas, rc, *stations[index].iterator, row_renderer); }
gcc_pure int LookupMode(const TCHAR *name) const { for (unsigned i = 0, size = modes.size(); i < size; ++i) if (modes[i] == name) return i; return -1; }
void NOAAListWidget::OpenDetails(unsigned index) { assert(index < stations.size()); dlgNOAADetailsShowModal(UIGlobals::GetMainWindow(), stations[index].iterator); UpdateList(); }
inline void WifiListWidget::Append(const WifiConfiguredNetworkInfo &src) { auto &dest = networks.append(); dest.bssid = src.bssid; dest.ssid = src.ssid; dest.id = src.id; dest.signal_level = -1; dest.old_configured = false; }
static void SetFormCaption() { StaticString<32> buffer; unsigned pageSize = grid_view->GetNumColumns() * grid_view->GetNumRows(); unsigned lastPage = buttons.size() / pageSize; buffer.Format(_T("Quick Menu %d/%d"), grid_view->GetCurrentPage() + 1, lastPage + 1); wf->SetCaption(buffer); }
void MutateTaskPointRenderer::OnPaintItem(Canvas &canvas, PixelRect rc, unsigned DrawListIndex) { assert(DrawListIndex < point_types.size()); if (point_types[DrawListIndex] == current_type) rc.left = row_renderer.DrawColumn(canvas, rc, _T("*")); row_renderer.DrawTextRow(canvas, rc, OrderedTaskPointName(point_types[DrawListIndex])); }
bool dlgTaskPointType(OrderedTask &task, const unsigned index) { point_types.clear(); task.GetFactory().GetValidTypes(index) .CopyTo(std::back_inserter(point_types)); if (point_types.empty()) { assert(1); return false; } if (point_types.size() == 1) return SetPointType(task, index, point_types[0]); const auto &point = task.GetPoint(index); const auto current_type = task.GetFactory().GetType(point); unsigned initial_index = 0; const auto b = point_types.begin(), e = point_types.end(); auto i = std::find(b, e, current_type); if (i != e) initial_index = std::distance(b, i); MutateTaskPointRenderer item_renderer(current_type); int result = ListPicker(_("Task Point Type"), point_types.size(), initial_index, item_renderer.CalculateLayout(UIGlobals::GetDialogLook()), item_renderer, false, nullptr, TPTypeItemHelp); return result >= 0 && SetPointType(task, index, point_types[result]); }
bool dlgTaskPointType(OrderedTask** task, const unsigned index) { ordered_task = *task; active_index = index; point = &ordered_task->GetPoint(active_index); point_types.clear(); ordered_task->GetFactory().GetValidTypes(index) .CopyTo(std::back_inserter(point_types)); if (point_types.empty()) { assert(1); return false; } if (point_types.size() == 1) return SetPointType(point_types[0]); unsigned initial_index = 0; const auto b = point_types.begin(), e = point_types.end(); auto i = std::find(b, e, get_point_type()); if (i != e) initial_index = std::distance(b, i); FunctionListItemRenderer item_renderer(OnPointPaintListItem); int result = ListPicker(_("Task Point Type"), point_types.size(), initial_index, Layout::Scale(18), item_renderer, false, nullptr, TPTypeItemHelp); return result >= 0 && SetPointType(point_types[result]); }
inline void WifiListWidget::SweepList() { unsigned cursor = GetList().GetCursorIndex(); for (int i = networks.size() - 1; i >= 0; --i) { NetworkInfo &info = networks[i]; if (info.old_visible && info.old_configured) { networks.remove(i); if (cursor > unsigned(i)) --cursor; } else { if (info.old_visible) info.signal_level = -1; if (info.old_configured) info.id = -1; } } GetList().SetCursorIndex(cursor); }
void WifiListWidget::UpdateList() { status.Clear(); if (EnsureConnected()) { wpa_supplicant.Status(status); for (auto &i : networks) i.old_visible = i.old_configured = true; UpdateScanResults(); UpdateConfigured(); /* remove items that are still marked as "old" */ SweepList(); } else networks.clear(); GetList().SetLength(networks.size()); UpdateButtons(); }
inline void NOAAListWidget::RemoveClicked() { unsigned index = GetList().GetCursorIndex(); assert(index < stations.size()); StaticString<256> tmp; tmp.Format(_("Do you want to remove station %s?"), stations[index].code.c_str()); if (ShowMessageBox(tmp, _("Remove"), MB_YESNO) == IDNO) return; noaa_store->erase(stations[index].iterator); noaa_store->SaveToProfile(); UpdateList(); }
static void OnPointPaintListItem(Canvas &canvas, const PixelRect rc, unsigned DrawListIndex) { assert(DrawListIndex < point_types.size()); StaticString<120> buffer; const TCHAR* text = OrderedTaskPointName(point_types[DrawListIndex]); if (point_types[DrawListIndex] == get_point_type()) buffer.Format(_T("*%s"), text); else buffer.Format(_T(" %s"), text); canvas.DrawText(rc.left + Layout::GetTextPadding(), rc.top + Layout::GetTextPadding(), buffer); }