We don't need random access to the entries, so a list fits just as well.
It also has better accessors we need.
dialog.show();
try {
- size_t i;
-
dialog.loadServerHistory();
dialog.serverName->clear();
- for(i = 0; i < dialog.serverHistory.size(); ++i)
+ for (const string& entry : dialog.serverHistory)
fltk_menu_add(dialog.serverName->menubutton(),
- dialog.serverHistory[i].c_str(), 0, nullptr);
+ entry.c_str(), 0, nullptr);
} catch (Exception& e) {
vlog.error("%s", e.str());
fl_alert(_("Unable to load the server history:\n\n%s"),
}
try {
- vector<string>::iterator elem = std::find(dialog->serverHistory.begin(), dialog->serverHistory.end(), servername);
+ list<string>::iterator elem = std::find(dialog->serverHistory.begin(), dialog->serverHistory.end(), servername);
// avoid duplicates in the history
if(dialog->serverHistory.end() == elem) {
dialog->serverHistory.insert(dialog->serverHistory.begin(), servername);
serverHistory.clear();
#ifdef _WIN32
- loadHistoryFromRegKey(serverHistory);
+ serverHistory = loadHistoryFromRegKey();
return;
#endif
}
// Save the last X elements to the config file.
- for(size_t idx=0; idx < serverHistory.size() && idx <= SERVER_HISTORY_SIZE; idx++)
- fprintf(f, "%s\n", serverHistory[idx].c_str());
+ size_t count = 0;
+ for (const string& entry : serverHistory) {
+ if (++count > SERVER_HISTORY_SIZE)
+ break;
+ fprintf(f, "%s\n", entry.c_str());
+ }
fclose(f);
}
#include <FL/Fl_Window.H>
#include <string>
-#include <vector>
+#include <list>
class Fl_Widget;
class Fl_Input_Choice;
protected:
Fl_Input_Choice *serverName;
- std::vector<std::string> serverHistory;
+ std::list<std::string> serverHistory;
std::string usedDir;
};
}
}
-void saveHistoryToRegKey(const vector<string>& serverHistory) {
+void saveHistoryToRegKey(const list<string>& serverHistory) {
HKEY hKey;
LONG res = RegCreateKeyExW(HKEY_CURRENT_USER,
L"Software\\TigerVNC\\vncviewer\\history", 0, nullptr,
char indexString[3];
try {
- while(index < serverHistory.size() && index <= SERVER_HISTORY_SIZE) {
+ for (const string& entry : serverHistory) {
+ if (index > SERVER_HISTORY_SIZE)
+ break;
snprintf(indexString, 3, "%d", index);
- setKeyString(indexString, serverHistory[index].c_str(), &hKey);
+ setKeyString(indexString, entry.c_str(), &hKey);
index++;
}
} catch (Exception& e) {
throw rdr::SystemException(_("Failed to close registry key"), res);
}
-void loadHistoryFromRegKey(vector<string>& serverHistory) {
+list<string> loadHistoryFromRegKey() {
HKEY hKey;
+ list<string> serverHistory;
LONG res = RegOpenKeyExW(HKEY_CURRENT_USER,
L"Software\\TigerVNC\\vncviewer\\history", 0,
if (res != ERROR_SUCCESS) {
if (res == ERROR_FILE_NOT_FOUND) {
// The key does not exist, defaults will be used.
- return;
+ return serverHistory;
}
throw rdr::SystemException(_("Failed to open registry key"), res);
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS)
throw rdr::SystemException(_("Failed to close registry key"), res);
+
+ return serverHistory;
}
static void getParametersFromReg(VoidParameter* parameters[],
#include "MonitorIndicesParameter.h"
#ifdef _WIN32
-#include <vector>
+#include <list>
#include <string>
#endif
char* loadViewerParameters(const char *filename);
#ifdef _WIN32
-void loadHistoryFromRegKey(std::vector<std::string>& serverHistory);
-void saveHistoryToRegKey(const std::vector<std::string>& serverHistory);
+std::list<std::string> loadHistoryFromRegKey();
+void saveHistoryToRegKey(const std::list<std::string>& serverHistory);
#endif
#endif