int RemoteModel::findRemoteByName(const QString &name) const { const int count = remoteCount(); for (int i = 0; i < count; i++) if (remoteName(i) == name) return i; return -1; }
QVariant RemoteModel::data(const QModelIndex &index, int role) const { const int row = index.row(); switch (role) { case Qt::DisplayRole: case Qt::EditRole: if (index.column() == 0) return remoteName(row); else return remoteUrl(row); default: break; } return QVariant(); }
bool RemoteModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (role != Qt::EditRole) return false; const QString name = remoteName(index.row()); const QString url = remoteUrl(index.row()); switch (index.column()) { case 0: if (name == value.toString()) return true; return renameRemote(name, value.toString()); case 1: if (url == value.toString()) return true; return updateUrl(name, value.toString()); default: return false; } }
void ArchivePublisher::enterSendingState() { assert(mState == PUBLISH_OBSERVED || mState == PUBLISH_SENDING); mState = PUBLISH_SENDING; FilePublishState minimumState = FILE_PUBLISH_UPLOADED; auto& hm = mApp.getHistoryManager(); std::weak_ptr<ArchivePublisher> weak(shared_from_this()); for (auto& pair : mFileInfos) { auto fi = pair.second; std::string name = fi->baseName_nogz(); switch (fi->getState()) { case FILE_PUBLISH_FAILED: break; case FILE_PUBLISH_NEEDED: fi->setState(FILE_PUBLISH_COMPRESSING); CLOG(DEBUG, "History") << "Compressing " << name; hm.compress(fi->localPath_nogz(), [weak, name](asio::error_code const& ec) { auto self = weak.lock(); if (!self) { return; } self->fileStateChange(ec, name, FILE_PUBLISH_COMPRESSED); }, true); break; case FILE_PUBLISH_COMPRESSING: break; case FILE_PUBLISH_COMPRESSED: fi->setState(FILE_PUBLISH_MAKING_DIR); CLOG(DEBUG, "History") << "Making remote directory " << fi->remoteDir(); hm.mkdir(mArchive, fi->remoteDir(), [weak, name](asio::error_code const& ec) { auto self = weak.lock(); if (!self) { return; } self->fileStateChange(ec, name, FILE_PUBLISH_MADE_DIR); }); break; case FILE_PUBLISH_MAKING_DIR: break; case FILE_PUBLISH_MADE_DIR: fi->setState(FILE_PUBLISH_UPLOADING); CLOG(INFO, "History") << "Publishing " << name; hm.putFile(mArchive, fi->localPath_gz(), fi->remoteName(), [weak, name](asio::error_code const& ec) { auto self = weak.lock(); if (!self) { return; } self->fileStateChange(ec, name, FILE_PUBLISH_UPLOADED); }); break; case FILE_PUBLISH_UPLOADING: break; case FILE_PUBLISH_UPLOADED: std::remove(fi->localPath_gz().c_str()); break; } minimumState = std::min(fi->getState(), minimumState); } if (minimumState == FILE_PUBLISH_FAILED) { CLOG(WARNING, "History") << "Some file-puts failed, retrying"; enterRetryingState(); } else if (minimumState == FILE_PUBLISH_UPLOADED) { CLOG(INFO, "History") << "All file-puts succeeded"; enterCommittingState(); } else { CLOG(DEBUG, "History") << "Some file-puts still in progress"; // Do nothing here; in-progress states have callbacks set up already // which will fire when they complete. } }
bool RemoteModel::removeRemote(int row) { QString output; QString error; bool success = m_client->synchronousRemoteCmd(m_workingDirectory, QStringList() << QLatin1String("rm") << remoteName(row), &output, &error); if (success) success = refresh(m_workingDirectory, &error); return success; }
// enumerates all network resources (hostnames) std::vector<std::string> getNetworkResourceNames(LPNETRESOURCE lpnr) { std::vector<std::string> hostnames; DWORD dwResult, dwResultEnum; HANDLE hEnum; DWORD cbBuffer = 16384; DWORD cEntries = -1; LPNETRESOURCE lpnrLocal; dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, // all network resources RESOURCETYPE_ANY, // all resources 0, // enumerate all resources lpnr, // (first time the function is called) &hEnum); // handle to the resource lpnrLocal = (LPNETRESOURCE)GlobalAlloc(GPTR, cbBuffer); if (dwResult != NO_ERROR || lpnrLocal == NULL) return hostnames; do { // Initialize the buffer ZeroMemory(lpnrLocal, cbBuffer); // Enumerate the network resources dwResultEnum = WNetEnumResource(hEnum, &cEntries, lpnrLocal, &cbBuffer); if (dwResultEnum == NO_ERROR) { // loop through the structures for (int i = 0; i < cEntries; ++i) { std::string remoteName(wstringToString(lpnrLocal[i].lpRemoteName)); // check if the resource name starts with '\\' if (remoteName.compare(0, 2, "\\\\") == 0) { remoteName = remoteName.substr(2); // remove the first '\\' // find other slashes and remove them if (remoteName.find("\\") != std::string::npos) remoteName = remoteName.substr(0, remoteName.find("\\")); // add to the hostnames vector if (std::find(hostnames.begin(), hostnames.end(), remoteName) == hostnames.end()) hostnames.push_back(remoteName); } // if the resource found is a resource container, call the function recursively if (RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER)) { std::vector<std::string> hn = getNetworkResourceNames(&lpnrLocal[i]); // append the vector returned by the recursive call to our vector if (!hn.empty()) for (auto name : hn) if (std::find(hostnames.begin(), hostnames.end(), remoteName) == hostnames.end()) hostnames.push_back(name); } } } else if (dwResultEnum != ERROR_NO_MORE_ITEMS) break; } while (dwResultEnum != ERROR_NO_MORE_ITEMS); // free the memory GlobalFree((HGLOBAL)lpnrLocal); // end enumeration dwResult = WNetCloseEnum(hEnum); if (dwResult != NO_ERROR) return std::vector<std::string>(); // empty vector return hostnames; }