void SettingsDialog::init() { /// Settings Window connect (mSettingsWindowUi.buttonBox, SIGNAL (accepted()), this, SLOT (onSettingsAccepted())); Model::Settings settings; { SF_SCHNEE_LOCK; settings = mController->umodel()->settings(); } sf::String user, server; splitUserServer (settings.userId, &user, &server); mSettingsWindowUi.usernameEdit->setText (qtString (user)); mSettingsWindowUi.serverEdit->setEditText(qtString (server)); mSettingsWindowUi.passwordEdit->setText (qtString (settings.password)); mSettingsWindowUi.useBoshCheckBox->setCheckState (settings.useBosh ? Qt::Checked : Qt::Unchecked); mSettingsWindowUi.fileDestinationEdit->setText (qtString (settings.destinationDirectory)); mSettingsWindowUi.echoServerIpEdit->setText (qtString (settings.echoServerIp)); mSettingsWindowUi.echoServerPortEdit->setValue (settings.echoServerPort); mSettingsWindowUi.autoConnectCheckBox->setCheckState (settings.autoConnect ? Qt::Checked : Qt::Unchecked); ::setDefaultServer(server); // TODO Should be done in controller if (mController->autostartAvailable()){ mSettingsWindowUi.autostartCheckBox->setCheckState (mController->autostartInstalled() ? Qt::Checked : Qt::Unchecked); } else { mSettingsWindowUi.autostartCheckBox->setEnabled (false); mSettingsWindowUi.autostartCheckBox->setHidden(true); } mFileDestinationChooseDialog = new QFileDialog (this, tr ("Choose Directory")); mFileDestinationChooseDialog->setAcceptMode (QFileDialog::AcceptOpen); mFileDestinationChooseDialog->setModal (true); mFileDestinationChooseDialog->setFileMode (QFileDialog::Directory); mFileDestinationChooseDialog->setOption (QFileDialog::ShowDirsOnly, true); connect (mFileDestinationChooseDialog, SIGNAL (fileSelected (const QString&)), this, SLOT (onFileDestinationSelected(const QString&))); connect (mSettingsWindowUi.fileDestinationChooseButton, SIGNAL (clicked()), mFileDestinationChooseDialog, SLOT (show())); }
//----------------------------------------------------------------------------- int qtTest::failedEqualityTest( const std::string& expectedValue, const std::string& actualValue, const QString& exprText, int line, const char* file, const char* func) { return this->failedEqualityTest(qtString(expectedValue), qtString(actualValue), exprText, line, file, func); }
void Controller::requestDirectory (const sf::Uri & uri) { SF_SCHNEE_LOCK; sf::FileGetting * getting = mModel->fileGetting(); sf::Error e = getting->requestDirectory(uri); if (e) { onError (err::CouldNotRequestDirectory, QObject::tr ("Could not request directory"), QObject::tr ("Could not request director %1 of %2, reason: %3") .arg (qtString(uri.host())).arg (qtString(uri.path().toString())).arg(toString(e))); } }
void Controller::updateSettings(const Model::Settings & s) { SF_SCHNEE_LOCK; mModel->setSettings (s); QSettings settings; settings.beginGroup("im"); settings.setValue("userId", qtString (s.userId)); settings.setValue("password", qtString (s.password)); settings.setValue("destinationDirectory", qtString (s.destinationDirectory)); settings.setValue("echoServerIp", qtString (s.echoServerIp)); settings.setValue("echoServerPort", QVariant (s.echoServerPort)); settings.setValue ("useBosh", s.useBosh); settings.setValue ("autoConnect", s.autoConnect); settings.endGroup (); }
QVariant TransferList::data (const QModelIndex & index, int role) const { if (role != Qt::DisplayRole) return QVariant(); int r = index.row (); if (r < 0 || (size_t)r >= mOpIds.size()) { sf::Log (LogWarning) << LOGID << "Strange row " << r << std::endl; return QVariant (); } AsyncOpId id = mOpIds[r]; assert (mTransfers.count(id) > 0); const TransferInfo & t = mTransfers.find(id)->second; int c = index.column (); switch (c) { case 0: return QVariant (qtString (sf::toString (t.uri))); break; case 1: return QVariant (qtString (t.filename)); break; case 2: if (mOutgoing) return QVariant (qtString (t.receiver)); else return QVariant (qtString (t.source)); break; case 3: return QVariant (formatSize (t.size)); break; case 4: return QVariant (((float)t.transferred / (float)t.size)); // [0 .. 1] break; case 5:{ return QVariant (formatSpeed (t.speed)); break; } case 6:{ int seconds = (int) (t.size / t.speed); return QVariant (formatInterval (seconds)); break; } case 7: if (t.state == sf::TransferInfo::ERROR){ return QVariant ("Error: " + QString (toString (t.error))); } return QVariant (tr(toString (t.state))); break; } return QVariant (); }
void Controller::init () { QSettings settings; Model::Settings s; settings.beginGroup("im"); s.userId = sfString (settings.value("userId","@sflx.net").toString()); s.resource = sfString (settings.value("resource", qtString (sf::net::hostName())).toString()); s.password = sfString (settings.value("password").toString()); s.destinationDirectory = sfString (settings.value("destinationDirectory", QDir::homePath()).toString()); s.echoServerIp = sfString (settings.value("echoServerIp", "82.211.19.149").toString()); if (s.echoServerIp == "62.48.92.13"){ // sflx.net moved! // workaround s.echoServerIp = "82.211.19.149"; } s.echoServerPort = settings.value("echoServerPort", "1234").toInt (); s.useBosh = settings.value("useBosh", false).toBool(); s.autoConnect = settings.value("autoConnect", false).toBool(); settings.endGroup (); { SF_SCHNEE_LOCK; mModel->setSettings(s); mModel->init (); mModel->beacon()->connections().conDetailsChanged() = dMemFun (this, &Controller::onConDetailsChanged); mModel->listTracker()->trackingUpdate() = dMemFun (this, &Controller::onTrackingUpdate); mModel->listTracker()->lostTracking() = dMemFun (this, &Controller::onLostTracking); mModel->fileGetting()->gotListing() = dMemFun (this, &Controller::onUpdatedListing); mModel->fileGetting()->updatedTransfer() = dMemFun (this, &Controller::onUpdatedIncomingTransfer); mModel->fileSharing()->updatedTransfer() = dMemFun (this, &Controller::onUpdatedOutgoingTransfer); sf::InterplexBeacon * beacon = mModel->beacon(); beacon->presences().peersChanged().add (sf::dMemFun (this, &Controller::onPeersChanged)); beacon->presences().onlineStateChanged().add (sf::dMemFun (this, &Controller::onOnlineStateChanged)); beacon->presences().subscribeRequest() = sf::dMemFun (this, &Controller::onUserSubscribeRequest); beacon->presences().serverStreamErrorReceived().add (sf::dMemFun (this, &Controller::onServerStreamErrorReceived)); // Set own features and activating protocol filter { const sf::String schneeProtocol = "http://sflx.net/protocols/schnee"; std::vector<sf::String> ownFeatures; ownFeatures.push_back (schneeProtocol); sf::Error e = beacon->presences().setOwnFeature(sf::String ("schneeflocke ") + sf::schnee::version(), ownFeatures); if (e) { sf::Log (LogError) << LOGID << "Could not set own feature" << std::endl; } else { mUserList->setFeatureFilter(schneeProtocol); } } } mGUI->init (); mGUI->call (sf::bind (&UserList::rebuildList, mUserList)); loadShares(); if (s.autoConnect){ xcall (abind (dMemFun (this, &Controller::onChangeConnection), DS_CONNECT)); } }
QVariant toQVariant (const sf::UserSet & userlist) { QStringList intermediate; for (sf::UserSet::const_iterator i = userlist.begin(); i != userlist.end(); i++) { intermediate.append(qtString(*i)); } return QVariant (intermediate); }
void Controller::loadShares () { { SF_SCHNEE_LOCK; QSettings settings; settings.beginGroup("share"); int count = settings.beginReadArray("shares"); for (int i = 0; i < count; i++) { settings.setArrayIndex(i); // do not read everything... sf::String shareName = sfString (settings.value("shareName").toString()); sf::String fileName = sfString (settings.value("fileName").toString()); bool forAll = settings.value("forAll").toBool(); sf::UserSet whom = toUserSet (settings.value("whom")); sf::Error e = mModel->fileSharing()->editShare(shareName, fileName, forAll, whom); if (e) { onError (err::CouldNotRestoreShare, QObject::tr ("Could not restore share"), QObject::tr ("Could not restore share %1, reason: %2") .arg (qtString(shareName)).arg (toString(e))); } } settings.endArray(); settings.endGroup(); } mGUI->call (boost::bind (&ShareList::update, mShareList)); }
void Controller::subscriptionRequestReply (const sf::UserId & userId, bool allow, bool alsoAdd) { SF_SCHNEE_LOCK; sf::Error e = mModel->beacon()->presences().subscriptionRequestReply(userId,allow,alsoAdd); if (e) { onError(err::CouldNotSubscribeReplyUser, QObject::tr ("Subscription error"), QObject::tr("Could not allow other user %1 to subscribe, reason: %2") .arg(qtString(userId)).arg (toString(e))); } }
void Controller::addUser (const sf::UserId & userId) { SF_SCHNEE_LOCK; sf::Error e = mModel->beacon()->presences().subscribeContact (userId); if (e) { onError(err::CouldNotAddUser, QObject::tr ("Could not add user"), QObject::tr ("Could not add user %1, reason: %2"). arg (qtString (userId)).arg (toString (e))); } }
void Controller::saveShares () { sf::FileSharing::FileShareInfoVec shares; { SF_SCHNEE_LOCK; shares = mModel->fileSharing()->shared(); } QSettings settings; settings.beginGroup("share"); settings.beginWriteArray("shares", shares.size()); for (size_t i = 0; i < shares.size(); i++) { settings.setArrayIndex((int)i); const sf::FileSharing::FileShareInfo & info = shares[i]; settings.setValue("shareName", qtString(info.shareName)); settings.setValue("path", qtString (info.path.toString())); settings.setValue("fileName", qtString (info.fileName)); settings.setValue("forAll", info.forAll); settings.setValue("whom", toQVariant(info.whom)); } settings.endArray(); settings.endGroup(); }
void Controller::onConnectHostForTrackingResult (sf::Error result, const sf::HostId & hostId) { if (result) { mGUI->call (sf::bind (&UserList::onLostTracking, mUserList, hostId)); onError (err::CouldNotConnectRemoteHost, QObject::tr ("Could not connect remote host"), QObject::tr ("Could not connect remote host %1").arg (qtString(hostId))); return; } sf::SharedListTracker * tracker = mModel->listTracker(); sf::Error e = tracker->trackShared (hostId); if (e) { mGUI->onError (err::CouldNotTrackShared, QObject::tr ("Could not track"), QObject::tr ("Could not track files of %1, reason: %2").arg(qtString(hostId)).arg(toString (e))); } }
void Controller::onServerStreamErrorReceived (const sf::String & text) { onError (err::ServerSentError, QObject::tr ("Server stream error"), QObject::tr ("Received a server stream error:<br/> <b>%1</b>").arg(qtString(text))); }
void Controller::removeUser (const sf::UserId & userId) { SF_SCHNEE_LOCK; sf::Error e = mModel->beacon()->presences().removeContact (userId); if (e) { onError(err::CouldNotRemoveUser, QObject::tr("User Removal"), QObject::tr ("Could not remove use %1, reason: %2").arg(qtString(userId)).arg(toString(e))); } }
bool pgConn::Initialize() { // Set client encoding to Unicode/Ascii, Datestyle to ISO, and ask for notices. if (PQstatus(conn) == CONNECTION_OK) { connStatus = PGCONN_OK; PQsetNoticeProcessor(conn, pgNoticeProcessor, this); wxString sql = wxT("SET DateStyle=ISO;\nSET client_min_messages=notice;\n"); if (BackendMinimumVersion(9, 0)) sql += wxT("SET bytea_output=escape;\n"); sql += wxT("SELECT oid, pg_encoding_to_char(encoding) AS encoding, datlastsysoid\n") wxT(" FROM pg_database WHERE "); if (save_oid) sql += wxT("oid = ") + NumToStr(save_oid); else { // Note, can't use qtDbString here as we don't know the server version yet. wxString db = save_database; db.Replace(wxT("\\"), wxT("\\\\")); db.Replace(wxT("'"), wxT("''")); sql += wxT("datname=") + qtString(db); } pgSet *set = ExecuteSet(sql); if (set) { if (set->ColNumber(wxT("\"datlastsysoid\"")) >= 0) needColQuoting = true; lastSystemOID = set->GetOid(wxT("datlastsysoid")); dbOid = set->GetOid(wxT("oid")); wxString encoding = set->GetVal(wxT("encoding")); if (encoding != wxT("SQL_ASCII") && encoding != wxT("MULE_INTERNAL")) { encoding = wxT("UNICODE"); conv = &wxConvUTF8; } else conv = &wxConvLibc; wxLogInfo(wxT("Setting client_encoding to '%s'"), encoding.c_str()); if (PQsetClientEncoding(conn, encoding.ToAscii())) { wxLogError(wxT("%s"), GetLastError().c_str()); } delete set; // Switch to the requested default role if supported by backend if (dbRole != wxEmptyString && BackendMinimumVersion(8, 1)) { sql = wxT("SET ROLE TO "); sql += qtIdent(dbRole); pgSet *set = ExecuteSet(sql); if (set) delete set; else return false; } return true; } } return false; }