/** * Puush upload the clipboard * @brief Systray::uploadClipboard */ void Systray::uploadClipboard() { if (!isLoggedIn()) return; QString text = QApplication::clipboard()->text(); // just look for "file://" and upload it, else just upload the text itself as a text file if (text.isEmpty()) { return; } else if (text.contains("file://")) { Upload *u = new Upload(text); connect(u, SIGNAL(started()), this, SLOT(puushStarted())); connect(u, SIGNAL(finished(QString)), this, SLOT(puushDone(QString))); } else { QTemporaryFile file; // The file is deleted too soon before it can be uploaded since the upload is in a callback. // Since it's in a temporary directory it'll get deleted eventually anyways... file.setAutoRemove(false); if (file.open()) { file.write(text.toLocal8Bit().data()); Upload *u = new Upload(file.fileName()); connect(u, SIGNAL(started()), this, SLOT(puushStarted())); connect(u, SIGNAL(finished(QString)), this, SLOT(puushDone(QString))); } else { trayIcon->showMessage("puush-qt", tr("Error opening temporary file for writing!"), QSystemTrayIcon::Critical); } } }
void Player::showTeamChange(bool n) { if (!isLoggedIn()) return; //INV BEHAV showteam() = n; emit updated(id()); }
void OKSocialPluginAndroid::getMyProfile(int preferedPictureSize, void *userData, const std::vector<std::string> &additionalFields) { if (!isLoggedIn()) { if (_delegate) _delegate->onGetMyProfile({SocialPluginDelegate::Error::Type::NO_LOGIN, 0, ""}, userData, _emptyProfile); return; } std::string fields = "uid,first_name,last_name,email,birthday,gender"; for (const auto &field : additionalFields) fields += "," + field; auto picturesMapIterator = _picturesMap.lower_bound(preferedPictureSize); const auto &pictureField = (picturesMapIterator == _picturesMap.end()) ? _picturesMap.rbegin()->second : picturesMapIterator->second; fields += "," + _pictureIDKey + "," + pictureField; cocos2d::JniMethodInfo methodInfo; if (cocos2d::JniHelper::getStaticMethodInfo(methodInfo, HELPER_CLASS_NAME, "getMyProfile", "(Ljava/lang/String;JLjava/lang/String;Z)V")) { jstring jFields = methodInfo.env->NewStringUTF(fields.c_str()); jstring jPictureField = methodInfo.env->NewStringUTF(pictureField.c_str()); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, jFields, (jlong)userData, jPictureField, (jboolean)_debug); methodInfo.env->DeleteLocalRef(methodInfo.classID); // methodInfo.env->DeleteLocalRef(jFields); // TODO // methodInfo.env->DeleteLocalRef(jPictureField); // TODO } }
void Player::ladderChange(bool n) { if (!isLoggedIn()) return;//INV BEHAV ladder() = n; emit updated(id()); }
void Player::autoKick() { if (!isLoggedIn()) { blockSignals(false); // In case we autokick an alt that was already disconnected disconnected(); } }
void Systray::openAccount() { if (!isLoggedIn()) return; QString key = s.value(Settings::ACCOUNT_API_KEY).toString(); openUrl(QUrl(s.value(Settings::BASE_URL).toString() + "login/go/?k=" + key)); }
void Apply(User* u) { if (!isLoggedIn(u)) { u->WriteServ("NOTICE %s :*** NOTICE -- You need to identify via SASL to use this server (your host is %s-Lined).", u->nick.c_str(), type.c_str()); ServerInstance->Users->QuitUser(u, type + "-Lined: "+this->reason); } }
bool recordDatabase::addToRecord(Field field, int valueToAdd){ if (isLoggedIn()){ DatabaseEntry *prevValue[MAX_FIELDS]; bool recordGotten = getRecord({ &field }, 1, prevValue); if (recordGotten){ return updateRecord(field, prevValue[0]->intValue + valueToAdd, false); } } return false; }
void Player::ladderChange(bool n) { if (!isLoggedIn()) return;//INV BEHAV if (state()[LadderEnabled] == n) { return; } state().setFlag(LadderEnabled, n); relay().notifyOptionsChange(id(), away(), n); }
void VKApi::method(const QString &method, const QMap<QString, QString> params, std::function< void(const QJsonDocument*, QNetworkReply::NetworkError) > callback ) { QUrl url( kApiBaseUrl + method ); QUrlQuery q; if (!params.empty()) { for (const auto& key : params) { q.addQueryItem( key, params.value(key) ); } } if (isLoggedIn()) q.addQueryItem("access_token", accessToken); url.setQuery(q); QNetworkRequest req; req.setUrl(url); qDebug() << "Sending request to: " << req.url().toString() << "\n"; auto reply = net.get(req); connect(reply, &QNetworkReply::finished, [reply, callback]() { QJsonDocument* json = 0; QJsonDocument jsonDoc; QNetworkReply::NetworkError error = reply->error(); qDebug() << "Finished reply: " << reply << "\n"; if (reply->error() != QNetworkReply::NetworkError::NoError) { qDebug() << "Network error: " << reply->errorString() << "\n"; } else { QJsonParseError parseErr; auto data = reply->readAll(); jsonDoc = QJsonDocument::fromJson(data , &parseErr ); qDebug() << "got response <" << reply->url() << ">\n" << data << "\n\n\n"; if (parseErr.error != QJsonParseError::NoError) { qDebug() << "failed to parse json: " << parseErr.errorString() << "\n"; error = QNetworkReply::NetworkError::UnknownContentError; } else if (!jsonDoc.object().contains("response")) { qDebug() << "bad json.\n"; error = QNetworkReply::NetworkError::UnknownContentError; } else { jsonDoc = QJsonDocument( jsonDoc.object().value( "response" ).toArray().at(0).toObject() ); json = &jsonDoc; } } if (callback) callback(json, error); reply->deleteLater(); }); }
/** * Puush capture area screenshot. * @brief Systray::selectAreaScreenshot */ void Systray::selectAreaScreenshot() { if (!isLoggedIn()) return; QString fileName = getTempPath(); Screenshot *ss = new Screenshot(fileName); connect(ss, SIGNAL(finished(int, QString, QString)), this, SLOT(screenshotDone(int, QString, QString))); ss->selectArea(); }
void IRCServer::sendCommandsInQueue() { if (isLoggedIn()) { while(!commandsInQueue_m.isEmpty()) { QByteArray command = commandsInQueue_m.takeFirst(); send(command); } } }
void IRCServer::sendCommandAsap(const QByteArray& command) { qDebug() << command; if (isLoggedIn()) send(command); else { commandsInQueue_m.push_back(command); enqueuedCommand(); } }
bool recordDatabase::updateRecord(Field field, int value, bool onlyIfGreater){ if (isLoggedIn()){ DatabaseEntry *prevValue[MAX_FIELDS]; bool recordGotten = getRecord({ &field }, 1, prevValue); if (recordGotten && (!onlyIfGreater || prevValue[0]->intValue < value)){ CString q = _T(""); q.Format(_T("UPDATE accounts SET %s = %d WHERE %s = %d"), fieldNames[field], value, dbFieldNames[ID], id); rawQuery(q,NULL); } } return false; }
bool Ledger::receiveAt(const QString& hfc_key, const QString& signing_key) { auto accountManager = DependencyManager::get<AccountManager>(); if (!accountManager->isLoggedIn()) { qCWarning(commerce) << "Cannot set receiveAt when not logged in."; QJsonObject result{ { "status", "fail" }, { "message", "Not logged in" } }; emit receiveAtResult(result); return false; // We know right away that we will fail, so tell the caller. } signedSend("public_key", hfc_key.toUtf8(), signing_key, "receive_at", "receiveAtSuccess", "receiveAtFailure"); return true; // Note that there may still be an asynchronous signal of failure that callers might be interested in. }
/* * This is the standard destructor and needs to be virtual to make * sure that if we subclass off this the right destructor will be * called. */ CKIRCProtocol::~CKIRCProtocol() { // first, kill the listener and free it setListener(NULL); // now handle the connection to the IRC server itself. if (isConnected()) { if (isLoggedIn()) { doQUIT("bye"); setIsLoggedIn(false); } mCommPort.disconnect(); } }
void Systray::activeWindowScreenshotTimed() { if (!isLoggedIn()) return; trayIcon->showMessage(tr("Select a window"), tr("Taking a screenshot in ") + QString::number(defaultSelectionTimeout) + tr(" seconds..."), QSystemTrayIcon::Information); numTime = defaultSelectionTimeout; timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updateActiveMessage())); timer->start(1000); }
/** * Puush upload a file via the open file dialog. * @brief Systray::uploadFile */ void Systray::uploadFile() { if (!isLoggedIn()) return; QString fileName = QFileDialog::getOpenFileName(NULL, tr("Upload file")); if (fileName == "") return; Upload *u = new Upload(fileName); connect(u, SIGNAL(started()), this, SLOT(puushStarted())); connect(u, SIGNAL(finished(QString)), this, SLOT(puushDone(QString))); }
bool recordDatabase::addUser(CString name, CString pass){ try{ CString q = _T(""); q.Format(_T("INSERT INTO accounts (%s,%s) VALUES ('%s','%s');"), dbFieldNames[USERNAME], dbFieldNames[PASSWORD],name, pass); rawQuery(q,NULL); logIn(name, pass); if (isLoggedIn()){ return true; } } catch (int e){ id = -1; return false; } }
bool recordDatabase::removeUser(){ if (isLoggedIn()){ try{ CString q = _T(""); q.Format(_T("DELETE FROM accounts WHERE %s=%d"), dbFieldNames[ID],id); rawQuery(q,NULL); logOut(); return true; } catch (int e){ return false; } } return false; }
void Systray::historyPlaceholder() { historyMenu->clear(); // Just put something in the history menu in case the menu doesn't get updated. QAction *none = new QAction(); if (isLoggedIn(false)) none->setText("Not fetched... Try left clicking the tray icon."); else none->setText("Not logged in..."); none->setEnabled(false); historyMenu->addAction(none); }
bool recordDatabase::logIn(CString name, CString pass){ try{ CString q = _T(""); q.Format(_T("SELECT %d FROM accounts WHERE username == '%s' AND password == '%s';"),dbFieldNames[ID],name,pass); DatabaseEntry *results[MAX_RESULT_SIZE][MAX_FIELDS]; //clearResults(results); rawQuery(q,results); if (results[0][0]->gotten){ id = results[0][0]->intValue; } return isLoggedIn(); } catch (int e){ id = -1; return false; } }
bool recordDatabase::getRecord(Field fields[], int numFields, DatabaseEntry *result[MAX_FIELDS]){ if (isLoggedIn()){ CString q = _T(""); CString fieldsStr = _T(""); for (int i = 0; i < numFields; i++){ fieldsStr += fieldNames[fields[i]]; } q.Format(_T("SELECT %s FROM accounts WHERE %s = %d"), fieldsStr, dbFieldNames[ID], id); DatabaseEntry *results[MAX_RESULT_SIZE][MAX_FIELDS]; clearResults(results); rawQuery(q,results); result = results[0]; return true; } return false; }
void VKApi::login() { if (isLoggedIn() || loginView) { return; } auto webView = new QWebView(); webView->setAttribute(Qt::WA_DeleteOnClose, true); auto url = getLoginUrl(); webView->load( url ); connect(webView, SIGNAL(urlChanged(QUrl)), this, SLOT(loginUrlChanged(const QUrl&))); connect(webView, &QWebView::destroyed, [this](){ this->loginView = 0; }); webView->show(); loginView = webView; }
void OKSocialPluginAndroid::logout() { if (!isLoggedIn()) { return; } _accessToken.clear(); _userID.clear(); cocos2d::JniMethodInfo methodInfo; if (cocos2d::JniHelper::getStaticMethodInfo(methodInfo, HELPER_CLASS_NAME, "logout", "(Z)V")) { methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, (jboolean)_debug); methodInfo.env->DeleteLocalRef(methodInfo.classID); } if (_delegate) _delegate->onLogout({SocialPluginDelegate::Error::Type::SUCCESS, 0, ""}); }
void LoginDialog::toggleAction() { auto accountManager = DependencyManager::get<AccountManager>(); QAction* loginAction = Menu::getInstance()->getActionForOption(MenuOption::Login); Q_CHECK_PTR(loginAction); static QMetaObject::Connection connection; if (connection) { disconnect(connection); } if (accountManager->isLoggedIn()) { // change the menu item to logout loginAction->setText("Logout " + accountManager->getAccountInfo().getUsername()); connection = connect(loginAction, &QAction::triggered, accountManager.data(), &AccountManager::logout); } else { // change the menu item to login loginAction->setText("Log In / Sign Up"); connection = connect(loginAction, &QAction::triggered, [] { LoginDialog::showWithSelection(); }); } }
/* * This method will log out any logged in user and break the * established connection to the IRC host. This is useful * when "shutting down" as it takes care of all the * possibilities in one fell swoop. */ void CKIRCProtocol::disconnect() { // first, stop the listener stopListener(); // now handle the connection to the IRC server itself. if (isConnected()) { if (isLoggedIn()) { doQUIT("bye"); setIsLoggedIn(false); } { CKStackLocker lockem(&mCommPortMutex); mCommPort.disconnect(); } // clear out all the channels we joined clearChannelList(); } }
/* * This method checks to see if the two CKIRCProtocols are equal to * one another based on the values they represent and *not* on the * actual pointers themselves. If they are equal, then this method * returns true, otherwise it returns false. */ bool CKIRCProtocol::operator==( const CKIRCProtocol & anOther ) const { bool equal = true; if ((getHostname() != anOther.getHostname()) || (getPort() != anOther.getPort()) || (mCommPort != anOther.mCommPort) || (isLoggedIn() != anOther.isLoggedIn()) || (getPassword() != anOther.getPassword()) || (getNickname() != anOther.getNickname()) || (getUserHost() != anOther.getUserHost()) || (getUserServer() != anOther.getUserServer()) || (getRealName() != anOther.getRealName()) || (mChannelList != anOther.mChannelList) || (mResponders != anOther.mResponders)) { equal = false; } return equal; }
ModResult OnCheckReady(LocalUser* user) { /*I'm afraid that using the normal xline methods would then result in this line being checked at the wrong time.*/ if (!isLoggedIn(user)) { XLine* locallines = ServerInstance->XLines->MatchesLine("A", user); XLine* globallines = ServerInstance->XLines->MatchesLine("GA", user); if (locallines) { user->WriteServ("NOTICE %s :*** NOTICE -- You need to identify via SASL to use this server (your host is A-Lined).", user->nick.c_str()); ServerInstance->Users->QuitUser(user, "A-Lined: "+locallines->reason); return MOD_RES_DENY; } else if (globallines) { user->WriteServ("NOTICE %s :*** NOTICE -- You need to identify via SASL to use this server (your host is GA-Lined).", user->nick.c_str()); ServerInstance->Users->QuitUser(user, "GA-Lined: "+globallines->reason); return MOD_RES_DENY; } } return MOD_RES_PASSTHRU; }
void Player::changeTier(quint8 teamNum, const QString &newtier) { if (!isLoggedIn()) { return; } if (teamNum >= teamCount()) { return; } if (team(teamNum).tier == newtier) return; if (battling()) { sendMessage(tr("You can't change tiers while battling.")); return; } if (!TierMachine::obj()->exists(newtier)) { sendMessage(tr("The tier %1 doesn't exist!").arg(newtier)); return; } if (!TierMachine::obj()->isValid(team(teamNum), newtier)) { Tier *tier = &TierMachine::obj()->tier(newtier); if (!tier->allowGen(team(teamNum).gen)) { sendMessage(tr("The generation of your team (%1) is invalid for the tier %2 which is in generation %3.").arg(GenInfo::Version(team(teamNum).gen), tier->name(), GenInfo::Version(tier->gen()))); return; } QList<int> indexList; for(int i = 0; i < 6; i++) { if (tier->isBanned(team(teamNum).poke(i))) { indexList.append(i); } } if (indexList.size() > 0) { foreach(int i, indexList) { sendMessage(tr("The Pokemon '%1' is banned on tier '%2' for the following reasons: %3").arg(PokemonInfo::Name(team(teamNum).poke(i).num()), newtier, tier->bannedReason(team(teamNum).poke(i)))); }