void DirectoryPickerDialog::showEvent(QShowEvent *) { QList<QTreeWidgetItem *> items; apisock *conn; binresult *res, *result, *rn; binresult root; QByteArray auth=app->settings->get("auth").toUtf8(); if (!(conn=app->getAPISock())){ showError("Could not connect to server. Check your Internet connection."); return; } ui->dirtree->clear(); ui->dirtree->setColumnCount(1); ui->dirtree->setHeaderLabels(QStringList("Name")); res=send_command(conn, "listfolder", P_LSTR("auth", auth.constData(), auth.size()), P_STR("filtermeta", "contents,folderid,name"), P_NUM("folderid", 0), P_BOOL("recursive", 1), P_BOOL("nofiles", 1), P_BOOL("noshares", onlyMine)); api_close(conn); result=find_res(res, "result"); if (!result){ showError("Could not connect to server. Check your Internet connection."); free(res); return; } if (result->num!=0){ showError(find_res(res, "error")->str); free(res); return; } if (showRoot){ root.type=PARAM_ARRAY; root.length=1; root.array=&rn; rn=find_res(res, "metadata"); result=&root; } else result=find_res(find_res(res, "metadata"), "contents"); items=binresToQList(result); ui->dirtree->insertTopLevelItems(0, items); ui->dirtree->sortByColumn(0, Qt::AscendingOrder); if (items.count()){ ui->dirtree->setCurrentItem(items[0]); ui->dirtree->expandItem(items[0]); } free(res); }
static QList<QTreeWidgetItem *> binresToQList(binresult *res){ QList<QTreeWidgetItem *> items; QTreeWidgetItem *item; binresult *e; quint32 i; for (i=0; i<res->length; i++){ e=res->array[i]; item=new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(find_res(e, "name")->str))); item->setData(1, Qt::UserRole, (qulonglong)find_res(e, "folderid")->num); item->addChildren(binresToQList(find_res(e, "contents"))); items.append(item); } return items; }
void PCloudApp::mount() { if (this->authentication != ""){ QByteArray auth=this->authentication.toUtf8(); apisock *conn=getAPISock(); binresult *res, *result; QByteArray err; if (!conn) return; res=send_command(conn, "userinfo", P_LSTR("auth", auth.constData(), auth.size()), P_BOOL("getauth", 1)); api_close(conn); result=find_res(res, "result"); if (!result){ free(res); return; } if (result->num!=0){ free(res); return; } userLogged(res, err, true); free(res); } }
void DirectoryPickerDialog::newFolder() { if (!ui->dirtree->currentItem()) return; quint64 folderid=ui->dirtree->currentItem()->data(1, Qt::UserRole).toULongLong(); QString newdir=QInputDialog::getText(this, "Create Folder", "New folder name"); if (!newdir.length()) return; QByteArray auth=app->settings->get("auth").toUtf8(); QByteArray bnewdir=newdir.toUtf8(); apisock *conn; binresult *res, *result; QTreeWidgetItem *item; if (!(conn=app->getAPISock())){ showError("Could not connect to server. Check your Internet connection."); return; } res=send_command(conn, "createfolder", P_LSTR("auth", auth.constData(), auth.size()), P_LSTR("name", bnewdir.constData(), bnewdir.size()), P_NUM("folderid", folderid)); api_close(conn); result=find_res(res, "result"); if (!result){ showError("Could not connect to server. Check your Internet connection."); free(res); return; } if (result->num!=0){ showError(find_res(res, "error")->str); free(res); return; } item=new QTreeWidgetItem((QTreeWidget*)0, QStringList(newdir)); item->setData(1, Qt::UserRole, (qulonglong)find_res(find_res(res, "metadata"), "folderid")->num); ui->dirtree->currentItem()->addChild(item); ui->dirtree->sortByColumn(0, Qt::AscendingOrder); ui->dirtree->setCurrentItem(item); free(res); }
int main() { // freopen("data.txt","r",stdin); while(scanf("%s",s[len]) != EOF) { if(strcmp(s[len],"#") == 0) break; len++; } low_cas(); memset(is_ana, false, sizeof(is_ana)); find_ana(); find_res(); for(int j = 0;j < len;j++) puts(res[j]); // puts(alp_s[0]); return 0; }
void PCloudApp::setUser(binresult *userinfo, bool rememebr){ emit logInSignal(find_res(userinfo, "auth")->str, find_res(userinfo, "email")->str, (quint64)find_res(userinfo, "userid")->num, find_res(userinfo, "emailverified")->num, find_res(userinfo, "premium")->num, (quint64)find_res(userinfo, "quota")->num, (quint64)find_res(userinfo, "usedquota")->num, rememebr); /* emitting signal should be enough * it seems that it is very important to have q-type parameters to this one * QString auth = find_res(userinfo, "auth")->str; QString email = find_res(userinfo, "email")->str; uint64_t uid = find_res(userinfo, "userid")->num; emit logInSignal(auth, email, uid, remember); logIn(auth, email, uid, remember); */ }
void RegisterWindow::doRegister(){ if (!ui->accepttos->checkState()){ setError("Registration only possible upon acceptance of terms."); return; } if (ui->password->text().length()<6){ setError("Password too short - minimum 6 characters."); return; } if (ui->password->text()!=ui->confirmpassword->text()){ setError("Password confirmation does not match."); return; } QByteArray email=ui->email->text().toUtf8(); QByteArray password=ui->password->text().toUtf8(); apisock *conn; binresult *res, *result; QByteArray err; quint64 type=0; #if defined(Q_OS_WIN) type=5; #elif defined(Q_OS_LINUX) type=7; #elif defined(Q_OS_MAC) type=6; #endif if (!(conn=app->getAPISock())){ setError("Connection to server failed."); return; } res=send_command(conn, "register", P_STR("termsaccepted", "yes"), P_LSTR("mail", email.constData(), email.size()), P_LSTR("password", password.constData(), password.size()), P_NUM("os", type)); result=find_res(res, "result"); if (!result){ setError("Connection to server failed."); free(res); api_close(conn); return; } if (result->num!=0){ setError(find_res(res, "error")->str); free(res); api_close(conn); return; } res=send_command(conn, "userinfo", P_LSTR("username", email.constData(), email.size()), P_LSTR("password", password.constData(), password.size()), P_BOOL("getauth", 1)); api_close(conn); result=find_res(res, "result"); if (!result){ setError("Connection to server failed."); free(res); return; } if (result->num!=0){ setError(find_res(res, "error")->str); free(res); return; } if (!app->userLogged(res, err, false)) setError(err); else{ setError(""); ui->password->clear(); ui->confirmpassword->clear(); hide(); } free(res); }
bool PCloudApp::userLogged(binresult *userinfo, QByteArray &err, bool remember){ if (isMounted()){ setUser(userinfo, remember); return true; } else{ #ifdef Q_OS_WIN if (find_res(userinfo, "auth")){ if (!settings->isSet("path") || !settings->get("path").toUtf8()[0]){ QString path("a:"); path[0] = getFirstFreeDevice(); settings->set("path", path); } QString auth(find_res(userinfo, "auth")->str); if (remember){ settings->set("auth", auth); this->authentication = auth; } else settings->set("auth", ""); if (mountCmd(atol(settings->get("cachesize").toUtf8()), auth.toUtf8(), settings->geti("usessl"), settings->get("path").toUtf8()[0], err)){ Sleep(5*1000); setUser(userinfo, remember); return true; } return false; } else { err = "Invalid E-mail and Password combination."; return false; } #else QProcess process; QStringList params; #ifdef Q_OS_MAC params.append("-o"); params.append("volname=pCloud"); // Adding -o local may or may not be a good idea params.append("-o"); params.append("local"); #endif params.append("--auth"); params.append(find_res(userinfo, "auth")->str); if (settings->geti("usessl")) params.append("--ssl"); params.append("--cache"); params.append(settings->get("cachesize")); params.append(settings->get("path")); #ifdef Q_OS_MAC process.start("/usr/local/bin/mount.pfs", params); #else process.start("mount.pfs", params); #endif if (!process.waitForFinished()){ err="Error mounting filesystem."; return false; } if (process.exitCode()==0){ setUser(userinfo, remember); return true; } else { err=process.readAllStandardError(); return false; } #endif } }