コード例 #1
0
int AccountManager::saveAccount(const Account& account)
{
    Account new_account = account;
    bool account_exist = false;
    {
        QMutexLocker lock(&accounts_mutex_);
        for (size_t i = 0; i < accounts_.size(); i++) {
            if (accounts_[i] == account) {
                accounts_.erase(accounts_.begin() + i);
                account_exist = true;
                break;
            }
        }
        accounts_.insert(accounts_.begin(), new_account);
    }
    updateServerInfo(0);

    qint64 timestamp = QDateTime::currentMSecsSinceEpoch();

    char *zql;
    if (account_exist) {
        zql = sqlite3_mprintf(
            "UPDATE Accounts SET token = %Q, lastVisited = %Q, isShibboleth = %Q"
            "WHERE url = %Q AND username = %Q",
            // token
            new_account.token.toUtf8().data(),
            // lastVisited
            QString::number(timestamp).toUtf8().data(),
            // isShibboleth
            QString::number(new_account.isShibboleth).toUtf8().data(),
            // url
            new_account.serverUrl.toEncoded().data(),
            // username
            new_account.username.toUtf8().data());
    } else {
        zql = sqlite3_mprintf(
            "INSERT INTO Accounts(url, username, token, lastVisited, isShibboleth) VALUES (%Q, %Q, %Q, %Q, %Q) ",
            // url
            new_account.serverUrl.toEncoded().data(),
            // username
            new_account.username.toUtf8().data(),
            // token
            new_account.token.toUtf8().data(),
            // lastVisited
            QString::number(timestamp).toUtf8().data(),
            // isShibboleth
            QString::number(new_account.isShibboleth).toUtf8().data());
    }
    sqlite_query_exec(db, zql);
    sqlite3_free(zql);

    emit accountsChanged();

    return 0;
}
コード例 #2
0
int AccountManager::replaceAccount(const Account& old_account, const Account& new_account)
{
    {
        QMutexLocker lock(&accounts_mutex_);
        for (size_t i = 0; i < accounts_.size(); i++) {
            if (accounts_[i] == old_account) {
                // TODO copy new_account and old_account before this operation
                // we might have invalid old_account or new_account after it
                accounts_[i] = new_account;
                updateServerInfo(i);
                break;
            }
        }
    }

    qint64 timestamp = QDateTime::currentMSecsSinceEpoch();

    char *zql = sqlite3_mprintf(
        "UPDATE Accounts "
        "SET url = %Q, "
        "    username = %Q, "
        "    token = %Q, "
        "    lastVisited = %Q, "
        "    isShibboleth = %Q "
        "WHERE url = %Q "
        "  AND username = %Q",
        // new_url
        new_account.serverUrl.toEncoded().data(),
        // username
        new_account.username.toUtf8().data(),
        // token
        new_account.token.toUtf8().data(),
        // lastvisited
        QString::number(timestamp).toUtf8().data(),
        // isShibboleth
        QString::number(new_account.isShibboleth).toUtf8().data(),
        // old_url
        old_account.serverUrl.toEncoded().data(),
        // username
        new_account.username.toUtf8().data()
        );

    sqlite_query_exec(db, zql);
    sqlite3_free(zql);

    emit accountsChanged();

    return 0;
}
コード例 #3
0
ServerWiget::ServerWiget(QWidget *parent) :
    QWidget(parent)
{

    server=new NetServer();
     port = 1988;
    peers=new PeerWidget();
    m_grLayout=new QGridLayout(this);
    listWidget_peerList =new QListWidget();
    listWidget_Log=new QListWidget();

    peer_count=new QLCDNumber();
    peer_count->setSegmentStyle(QLCDNumber::Filled);

    m_hbLayout=new QHBoxLayout();
    m_hbLayout->addWidget(new QLabel("<span style=\"color:#0f615b;\">" + tr("Clients:") + "</span>"),Qt::AlignLeft);
    m_hbLayout->addStretch(50);
    m_hbLayout->addWidget(peer_count,Qt::AlignRight);
    server_Parameters=new QWidget();
    sp_gboxLayout=new QGridLayout();
     sp_gboxLayout->addWidget(new QLabel("<span style=\"color:#31cd69;\">" + tr("Server Info:") + "</span>"),0,0,1,2,Qt::AlignCenter);
    sp_gboxLayout->addLayout(m_hbLayout,1,0,1,2,Qt::AlignCenter);
    labelServerIP=new QLabel("<span style=\"color:#2343b3;\">" + getServerIP(2) + "</span>");
     labelServerIP2=new QLabel("<span style=\"color:#2343b3;\">" + getServerIP(4) + "</span>");
    sp_gboxLayout->addWidget(new QLabel("<span style=\"color:#0f615b;\">" + tr("Server IP:") + "</span>"),2,0,2,1,Qt::AlignLeft);
    sp_gboxLayout->addWidget(labelServerIP,2,1 ,Qt::AlignRight);
    sp_gboxLayout->addWidget(labelServerIP2,3,1 ,Qt::AlignRight);
        sp_gboxLayout->addWidget(new QLabel("<span style=\"color:#0f615b;\">" + tr("Port:") + "</span>"),4,0,1,1,Qt::AlignLeft);
    labelServerPort=new QLabel ("<span style=\"color:#2343b3;\">" + QString::number(port) + "</span>");
    sp_gboxLayout->addWidget(labelServerPort,4,1 ,Qt::AlignRight);
    UpdateServerInfo=new QPushButton("&Update info");
       sp_gboxLayout->addWidget(UpdateServerInfo,5,0,1,3,Qt::AlignCenter);
    sp_gboxLayout->setColumnStretch(1,2.0);
    server_Parameters->setLayout(sp_gboxLayout);
    m_grLayout->addWidget(listWidget_peerList,0,0,1,1,Qt::AlignLeft);
    m_grLayout->setColumnStretch(0,1);
    m_grLayout->setRowStretch(0,3.0);
    m_grLayout->setRowStretch(1,1);
    m_grLayout->addWidget(peers,0,1,1,1);
    m_grLayout->addWidget(listWidget_Log,1,1,1,1);
    m_grLayout->addWidget(server_Parameters,1,0);
    m_grLayout->setColumnStretch(1,4);
    labelServerStatus=new QLabel(tr("Server: ") + "<span style=\"color:#000088;\">" + tr("stopped") + "</span>");
    connect(UpdateServerInfo,SIGNAL(clicked()),this,SLOT(updateServerInfo()));
    connect(listWidget_peerList,SIGNAL(clicked(QModelIndex)),this,SLOT(on_listWidget_peerList_clicked(QModelIndex)));
    this->setLayout(m_grLayout);
    qDebug()<<"Server Widget created";
}
コード例 #4
0
void AccountManager::updateServerInfo()
{
    for (size_t i = 0; i < accounts_.size(); i++)
        updateServerInfo(i);
}