示例#1
0
void PapyrusDesktop::setPapyrusSync(PapyrusSync *ksync)
{
    p->sync = ksync;

    connect( p->sync, SIGNAL(syncStarted())      , SLOT(syncStarted())       );
    connect( p->sync, SIGNAL(syncProgress(qreal)), SLOT(syncProgress(qreal)) );
    connect( p->sync, SIGNAL(syncFinished())     , SLOT(syncFinished())      );
}
示例#2
0
void KaqazDesktop::setKaqazSync(KaqazSync *ksync)
{
    p->sync = ksync;

    connect( p->sync, SIGNAL(syncStarted())      , SLOT(syncStarted())       );
    connect( p->sync, SIGNAL(syncProgress(qreal)), SLOT(syncProgress(qreal)) );
    connect( p->sync, SIGNAL(syncFinished())     , SLOT(syncFinished())      );
}
示例#3
0
void MainWindow::closeWindow()
{
    sql::updateSyncStatus("mainWindowGeometry", QString::fromLatin1(saveGeometry().toBase64()));
    sql::updateSyncStatus("mainWidgetsSplitterState", QString::fromLatin1(ui->mainWidgetsSplitter->saveState().toBase64()));

    ui->actionClose->setDisabled(true);
    disconnect(EdamProtocol::GetInstance(), SIGNAL(syncFinished()), this, SLOT(syncFinished()));

    sync();

    qApp->quit();
}
void CalDavClient::reportRequestFinished()
{
    Report *request = qobject_cast<Report*>(sender());
    if (!request) {
        syncFinished(Buteo::SyncResults::INTERNAL_ERROR, QStringLiteral("Invalid request object"));
        return;
    }

    if (request->errorCode() != Buteo::SyncResults::NO_ERROR) {
        qWarning() << "REPORT request failed!" << request->errorString();
    }
    syncFinished(request->errorCode(), request->errorString());
}
示例#5
0
void ownCloudFolder::slotCSyncFinished()
{
    if (_csync->error())
        qDebug() << "    * owncloud csync thread finished with error";
    else
        qDebug() << "    * owncloud csync thread finished successfully";

#ifndef USE_WATCHER
    if( _csync->hasLocalChanges( _lastWalkedFiles ) ) {
        qDebug() << "Last walked files: " << _lastWalkedFiles << " against " << _csync->walkedFiles();
        qDebug() << "*** Local changes, lets do a full sync!" ;
        _localCheckOnly = false;
        _pollTimerCnt = 0;
        _lastWalkedFiles = -1;
        QTimer::singleShot( 0, this, SLOT(startSync( QStringList() )));
    } else {
        qDebug() << "     *** Finalize, pollTimerCounter is "<< _pollTimerCnt ;
        _lastWalkedFiles = _csync->walkedFiles();
    // TODO delete thread
    }
#endif
    emit syncFinished(_csync->error() ?
                          SyncResult(SyncResult::Error)
                        : SyncResult(SyncResult::Success));

}
示例#6
0
// Sends the next group in groupsToUpload and download status for
// next in groupsToDownload
void SyncMaster::processGroups() {
    fdb.checkSanity();
    // qDebug() << Q_FUNC_INFO << "Groups to upload: " << groupsToUpload.size() << " download: " << groupsToDownload.size();
    if(canceled) return;
    if (groupsToUpload.isEmpty() && groupsToDownload.isEmpty()) {
        emit syncFinished(true, QString::null);
        return;
    }
    // Do the uploading
    if(!groupsToUpload.isEmpty()) {
        ForumGroup *g = groupsToUpload.takeFirst();
        g->subscription()->setBeingSynced(true);
        g->setChangeset(rand());
        for(ForumThread *thread : g->values()) {
            Q_ASSERT(thread);
            messagesToUpload.append(thread->values());
        }
        connect(&protocol, SIGNAL(sendThreadDataFinished(bool, QString)), this, SLOT(sendThreadDataFinished(bool, QString)));
        protocol.sendThreadData(g, messagesToUpload);
        g->setHasChanged(false);
        g->commitChanges();
        messagesToUpload.clear();
        emit syncProgress(0, "Synchronizing " + g->name() + " in " + g->subscription()->alias() + "..");
        g->subscription()->setBeingSynced(false);
    }
void
GContactClient::networkError (int errorCode)
{
    FUNCTION_CALL_TRACE;

    // TODO: If interested, check the value of error. But
    // it is enough to say that it is a SYNC_CONNECTION_ERROR
    //emit syncFinished (Sync::SYNC_CONNECTION_ERROR);
    switch (errorCode)
    {
    case 400:
        // Bad request. Better to bail out, since it could be a problem with the
        // data format of the request/response
        mSyncStatus = Sync::SYNC_BAD_REQUEST;
        break;
    case 401:
        mSyncStatus = Sync::SYNC_AUTHENTICATION_FAILURE;
        break;
    case 403:
    case 408:
        mSyncStatus = Sync::SYNC_ERROR;
        break;
    case 500:
    case 503:
    case 504:
        // Server failures
        mSyncStatus = Sync::SYNC_SERVER_FAILURE;
        break;
    default:
        break;
    };

    emit syncFinished (mSyncStatus);
}
void EvernoteSync::startSync()
{
    m_storageManager->log("EvernoteSync::startSync()");
#ifndef QT_SIMULATOR
    if (!m_isSyncInProgress) {
        updateSyncStatusMessage("");
        m_isSyncInProgress = true;
        m_syncProgress = 0;
        emit isSyncingChanged();
        emit syncProgressChanged();
        bool alreadyConnected;
        bool requestOk = m_connectionManager->requestConnection(&alreadyConnected);
        if (alreadyConnected) {
            m_storageManager->log("startSync() Already connected");
        } else if (requestOk) {
            m_storageManager->log("startSync() Connection request succeeded");
        } else {
            m_storageManager->log("startSync() Connection request failed");
        }
        if (alreadyConnected) {
            networkConnected(); // else, this slot will get called when it does gets connected
        } else if (!requestOk) {
            m_isSyncInProgress = false;
            emit syncFinished(false, "Not connected to the internet");
        }
    }
#else
    m_isSyncInProgress = true;
    m_syncProgress = 0;
    emit isSyncingChanged();
    emit syncProgressChanged();
    networkConnected();
#endif
}
void EvernoteSync::networkDisconnected()
{
    m_storageManager->log(QString("EvernoteSync::networkDisconnected() sync_in_progress=%1 thread_running=%2").arg(m_isSyncInProgress).arg(m_isThreadRunning));
    if (m_isSyncInProgress) {
        cancel();
        emit syncFinished(false, "Not connected to the internet");
    }
}
示例#10
0
void RemoteSync::syncPushReply(WP::err code)
{
    if (code != WP::kOk)
        return;

    QByteArray data = fServerReply->readAll();

    fDatabase->updateLastSyncCommit(fRemoteStorage->getUid(), fDatabase->branch(), fSyncUid);
    emit syncFinished(WP::kOk);
}
void CalDavClient::startQuickSync()
{
    FUNCTION_CALL_TRACE;

    mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC()));
    mKCal::ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar);

    storage->open();
    storage->load(QDateTime::currentDateTime().toUTC().addMonths(-6).date(),
                  QDateTime::currentDateTime().toUTC().addMonths(12).date());

    // we add 2 seconds to ensure that the timestamp doesn't
    // fall prior to when the calendar db commit fs sync finalises.
    KDateTime fromDate(lastSyncTime().addSecs(2));
    LOG_DEBUG("\n\nLAST SYNC TIME = " << fromDate.toString() << "\n\n");

    KCalCore::Incidence::List inserted;
    KCalCore::Incidence::List modified;
    KCalCore::Incidence::List deleted;
    QString errorString;
    if (!loadStorageChanges(storage, fromDate, &inserted, &modified, &deleted, &errorString)) {
        storage->close();
        calendar->close();
        syncFinished(Buteo::SyncResults::INTERNAL_ERROR, errorString);
        return;
    }
    LOG_DEBUG("Changes: inserted = " << inserted.count()
              << "modified = " << modified.count()
              << "deleted = " << deleted.count());
    if (inserted.isEmpty() && modified.isEmpty() && deleted.isEmpty()) {
        // no local changes to send, just do a REPORT to pull updates from server
        retrieveETags();
    } else {
        for (int i=0; i<inserted.count(); i++) {
            Put *put = new Put(mNAManager, &mSettings);
            mRequests.insert(put);
            connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            put->createEvent(inserted[i]);
        }
        for (int i=0; i<modified.count(); i++) {
            Put *put = new Put(mNAManager, &mSettings);
            mRequests.insert(put);
            connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            put->updateEvent(modified[i]);
        }
        for (int i=0; i<deleted.count(); i++) {
            Delete *del = new Delete(mNAManager, &mSettings);
            mRequests.insert(del);
            connect(del, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            del->deleteEvent(deleted[i]);
        }
    }
    storage->close();
    calendar->close();
}
示例#12
0
文件: folder.cpp 项目: krnowak/mirall
Folder::Folder(const QString &alias, const QString &path, const QString& secondPath, QObject *parent)
    : QObject(parent)
      , _path(path)
      , _secondPath(secondPath)
      , _alias(alias)
      , _enabled(true)
      , _thread(0)
      , _csync(0)
      , _csyncError(false)
      , _csyncUnavail(false)
      , _csync_ctx(0)
{
    qsrand(QTime::currentTime().msec());

    _watcher = new FolderWatcher(path, this);

    MirallConfigFile cfg;
    _watcher->addIgnoreListFile( cfg.excludeFile(MirallConfigFile::SystemScope) );
    _watcher->addIgnoreListFile( cfg.excludeFile(MirallConfigFile::UserScope) );

    QObject::connect(_watcher, SIGNAL(folderChanged(const QStringList &)),
                     SLOT(slotChanged(const QStringList &)));

    _syncResult.setStatus( SyncResult::NotYetStarted );

    ServerActionNotifier *notifier = new ServerActionNotifier(this);
    connect(notifier, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(optionalGuiLog(QString,QString)));
    connect(this, SIGNAL(syncFinished(SyncResult)), this, SLOT(slotSyncFinished(SyncResult)));
    connect(this, SIGNAL(syncFinished(SyncResult)), notifier, SLOT(slotSyncFinished(SyncResult)));

    // check if the local path exists
    checkLocalPath();

    int polltime = cfg.remotePollInterval();
    qDebug() << "setting remote poll timer interval to" << polltime << "msec";
    _pollTimer.setInterval( polltime );
    QObject::connect(&_pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerTimeout()));
    _pollTimer.start();

    _syncResult.setFolder(alias);
}
示例#13
0
void Syncer::determineRemoteChanges(const QDateTime &, const QString &)
{
    m_cardDav = m_username.isEmpty()
              ? new CardDav(this, m_serverUrl, m_addressbookPath, m_accessToken)
              : new CardDav(this, m_serverUrl, m_addressbookPath, m_username, m_password);
    connect(m_cardDav, SIGNAL(remoteChanges(QList<KContacts::Addressee>,QList<KContacts::Addressee>,QList<KContacts::Addressee>)),
            this, SLOT(continueSync(QList<KContacts::Addressee>,QList<KContacts::Addressee>,QList<KContacts::Addressee>)));
    connect(m_cardDav, SIGNAL(upsyncCompleted()),
            this, SLOT(syncFinished()));
    connect(m_cardDav, SIGNAL(error(int)),
            this, SLOT(cardDavError(int)));
    m_cardDav->determineRemoteAMR();
}
void CalDavClient::nonReportRequestFinished()
{
    FUNCTION_CALL_TRACE;

    Request *request = qobject_cast<Request*>(sender());
    if (!request) {
        syncFinished(Buteo::SyncResults::INTERNAL_ERROR, QStringLiteral("Invalid request object"));
        return;
    }

    if (request->errorCode() != Buteo::SyncResults::NO_ERROR) {
        qWarning() << "Aborting sync," << request->command() << "failed!" << request->errorString();
        syncFinished(Buteo::SyncResults::INTERNAL_ERROR, request->errorString());
        return;
    }

    mRequests.remove(request);
    request->deleteLater();

    if (mRequests.isEmpty()) {
        // now we can send a REPORT
        retrieveETags();
    }
}
示例#15
0
void EvernoteSync::networkConnected()
{
    m_storageManager->log(QString("EvernoteSync::networkConnected() sync_in_progress=%1 thread_running=%2").arg(m_isSyncInProgress).arg(m_isThreadRunning));
    if (m_isSyncInProgress && !m_isThreadRunning) {
        bool isSyncOverMobileDataAllowed = (m_storageManager->retrieveSetting("Sync/syncUsingMobileData") || (!m_storageManager->retrieveEvernoteSyncData("FullSyncDone").toBool()));
        if ((!m_connectionManager->isIapConfigurationWifi()) && (!isSyncOverMobileDataAllowed)) {
            m_isSyncInProgress = false;
            emit isSyncingChanged();
            emit syncFinished(false, "Syncing over mobile data is disabled");
            return;
        }
        startSyncThreaded();
        m_isThreadRunning = true;
    }
}
示例#16
0
void SiteCopyFolder::analyzeStatus()
{
  QString out( _lastOutput );
  qDebug() << "Output: " << out;

  _ChangesHash.clear();

  QStringList items;
  QString action;

  QStringList li = out.split(QChar('\n'));
  foreach( QString l, li ) {
    if( l.startsWith( "sectstart|") ) {
      action = l.mid(10);
      qDebug() << "starting to parse " << action;
    }
    if( l.startsWith( "sectend|")) {
      action = l.mid(8);
      _ChangesHash.insert( action, items );
      items.clear();
    }
    if( l.startsWith( "item|" )) {
      QString item = l.mid(5);
      items << item;
    }

    if( l.startsWith("siteend") ) {
#if 0
      if( l.endsWith("unchanged") ) {
        // we are synced and don't do anything
        // emit statusChange( Unchanged );
          // FIXME: Bug handling
          emit syncFinished( SyncResult(SyncResult::Success) );
      } else if( l.endsWith("changed")) {
          startSiteCopy( "--update", Status );

        if( mLocalChangesSeen ) {
          // emit statusChange( SyncToNeeded );
        } else {
          // emit statusChange( SyncFromNeeded );
        }

      }
#endif
    }
  }
}
示例#17
0
ownCloudFolder::ownCloudFolder(const QString &alias,
                               const QString &mpath,
                               const QString &secondPath,
                               QObject *parent)
    : Folder(alias, mpath, secondPath, parent)
    , _thread(0)
    , _csync(0)
    , _csyncError(false)
    , _csyncUnavail(false)
    , _csync_ctx(0)
{
    ServerActionNotifier *notifier = new ServerActionNotifier(this);
    connect(notifier, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
    connect(this, SIGNAL(syncFinished(SyncResult)), notifier, SLOT(slotSyncFinished(SyncResult)));
    qDebug() << "****** ownCloud folder using watcher *******";
    // The folder interval is set in the folder parent class.
}
示例#18
0
void EvernoteSyncThread::run()
{
#ifndef QT_SIMULATOR
    connect(m_evernoteAccess, SIGNAL(finished(bool,QString)), SIGNAL(syncFinished(bool,QString)));
    connect(m_evernoteAccess, SIGNAL(loginError(QString)), SIGNAL(loginError(QString)));
    connect(m_evernoteAccess, SIGNAL(firstChunkDone()), SIGNAL(firstChunkDone()));
    connect(m_evernoteAccess, SIGNAL(syncProgressChanged(int)), SIGNAL(syncProgressChanged(int)));
    connect(m_evernoteAccess, SIGNAL(syncStatusMessage(QString)), SIGNAL(syncStatusMessage(QString)));
    connect(m_evernoteAccess, SIGNAL(fullSyncDoneChanged()), SIGNAL(fullSyncDoneChanged()));
    connect(m_evernoteAccess, SIGNAL(authTokenInvalid()), SIGNAL(authTokenInvalid()));
    connect(m_evernoteAccess, SIGNAL(rateLimitReached(int)), SIGNAL(rateLimitReached(int)));
    m_evernoteAccess->synchronize();
    m_evernoteAccess->disconnect(this);
#else
    emit syncProgressChanged(100);
    emit syncFinished(true, QLatin1String("Dummy sync"));
#endif
}
void
GContactClient::storeToLocal (QList<QContact> serverContacts)
{
    FUNCTION_CALL_TRACE;

    QMap<int, GContactsStatus> statusMap;
    LOG_DEBUG ("TOTAL SERVER CONTACTS:" << serverContacts.size ());

    if (mContactBackend->addContacts (serverContacts, statusMap))
    {
        // TODO: Saving succeeded. Update sync results
    } else
    {
        // TODO: Saving failed. Update sync results and probably stop sync
    }

    emit syncFinished (Sync::SYNC_DONE);
}
示例#20
0
void MainWindow::syncStarted(int count)
{
    ui->actionSync->setEnabled(false);
    if (loaded)
        return;    

    QProgressDialog* progress = new QProgressDialog("Syncing Notes...", "Abort Sync", 0, count, this);
    progress->setAutoReset(false);
    progress->setAutoClose(false);
    connect( EdamProtocol::GetInstance(), SIGNAL(syncProgress(int)), progress, SLOT(setValue(int)));
    connect(progress, SIGNAL(canceled()), EdamProtocol::GetInstance(), SLOT(cancelSync()));
    connect(progress, SIGNAL(canceled()), progress, SLOT(deleteLater()));
    connect(EdamProtocol::GetInstance(), SIGNAL(syncFinished()), progress, SLOT(close()));
    connect(EdamProtocol::GetInstance(), SIGNAL(syncRangeChange(int)), progress, SLOT(setMaximum(int)));
    progress->show();

    ui->statusbar->showMessage("Sync Started!", 5000);
}
void
GContactClient::fetchRemoteContacts (const int startIndex)
{
    FUNCTION_CALL_TRACE;

    /**
     o Get last sync time
     o Get etag value from local file system (this is a soft etag)
     o Connect finishedRequest to parseResults & network error slots
     o Use mTransport to perform network fetch
    */
    QDateTime syncTime = lastSyncTime ();
    if (!syncTime.isNull ())
        mTransport->setUpdatedMin (syncTime);

    if (startIndex != 1)
    {
        mTransport->setStartIndex (startIndex);
    }
    mTransport->setMaxResults (GConfig::MAX_RESULTS);
    if (mSlowSync == false)
        mTransport->setShowDeleted ();

    // FIXME: Fetching contacts using etag value as described in Google
    // data API does not seem to work
    // https://developers.google.com/gdata/docs/2.0/reference

    QString token = authToken ();
    if (token.isNull () || token.isEmpty ())
    {
        LOG_CRITICAL ("Auth token is null");
        // Better error would be SYNC_CONFIG_ERROR
        emit syncFinished (Sync::SYNC_ERROR);
        return;
    }
    mTransport->setGDataVersionHeader ();
    mTransport->addHeader (QByteArray ("Authorization"),
                           QString ("Bearer " + token).toUtf8());

    mTransport->request (GTransport::GET);
}
void
GContactClient::abortSync (Sync::SyncStatus aStatus)
{
    FUNCTION_CALL_TRACE;
    Sync::SyncStatus state = Sync::SYNC_ABORTED;

    if (aStatus == Sync::SYNC_ERROR) {
        state = Sync::SYNC_CONNECTION_ERROR;
    }

    if( !this->abort (state) )
    {
        LOG_DEBUG( "Agent not active, aborting immediately" );
        syncFinished(Sync::SYNC_ABORTED);

    }
    else
    {
        LOG_DEBUG( "Agent active, abort event posted" );
    }
}
示例#23
0
QNetworkReply* NetworkAccess::syncGet(QUrl url) {

    working = true;

    networkReply = simpleGet(url);
    connect(networkReply, SIGNAL(metaDataChanged()),
            this, SLOT(syncMetaDataChanged()), Qt::QueuedConnection);
    connect(networkReply, SIGNAL(finished()),
            this, SLOT(syncFinished()), Qt::QueuedConnection);
    connect(networkReply, SIGNAL(error(QNetworkReply::NetworkError)),
            this, SLOT(error(QNetworkReply::NetworkError)), Qt::QueuedConnection);

    // A little trick to make this function blocking
    while (working) {
        // Do something else, maybe even network processing events
        qApp->processEvents();
    }

    networkReply->deleteLater();
    return networkReply;

}
示例#24
0
void ownCloudFolder::slotCSyncFinished()
{
    qDebug() << "-> CSync Finished slot with error " << _csyncError;

    if (_csyncError) {
        _syncResult.setStatus(SyncResult::Error);

        qDebug() << "  ** error Strings: " << _errors;
        _syncResult.setErrorStrings( _errors );
        qDebug() << "    * owncloud csync thread finished with error";
        if( _wipeDb ) wipe();
    } else if (_csyncUnavail) {
        _syncResult.setStatus(SyncResult::Unavailable);
    } else {
        _syncResult.setStatus(SyncResult::Success);
    }

    if( _thread && _thread->isRunning() ) {
        _thread->quit();
    }
    emit syncFinished( _syncResult );
}
bool CalDavClient::cleanUp()
{
    FUNCTION_CALL_TRACE;
    QStringList accountList = iProfile.keyValues(Buteo::KEY_ACCOUNT_ID);
    int accountId = 0;
    if (!accountList.isEmpty()) {
        QString aId = accountList.first();
        if (aId != NULL) {
            accountId = aId.toInt();
        }
    }

    mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC()));
    mKCal::ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar);
    storage->open();
    QString aId = QString::number(accountId);
    QString nbUid;
    mKCal::Notebook::List notebookList = storage->notebooks();
    LOG_DEBUG("Total Number of Notebooks in device = " << notebookList.count());
    Q_FOREACH (mKCal::Notebook::Ptr nbPtr, notebookList) {
        if(nbPtr->account() == aId) {
            nbUid = nbPtr->uid();
            storage->loadNotebookIncidences(nbUid);
            calendar->deleteAllIncidences();
            storage->deleteNotebook(nbPtr);
            break;
        }
    }
    storage->save();
    storage->close();
    calendar->close();

    if (nbUid.isNull() || nbUid.isEmpty()) {
        syncFinished(Buteo::SyncResults::INTERNAL_ERROR, QStringLiteral("Cannot find notebook UID, cannot save any events"));
        return false;
    }

    return true;
}
bool
GContactClient::startSync()
{
    /*
      1. If no previous sync, go for slow-sync. Fetch all contacts
         from server
      2. Check if previous sync happened (from SyncLog). If yes,
         fetch the time of last sync
      3. Using the last sync time, retrieve all contacts from server
         that were added/modified/deleted
      4. Fetch all added/modified/deleted items from device
      5. Check for conflicts. Take the default policy as "server-wins"
      6. Save the list from the server to device
      7. Push "client changes" - "conflicting items" to the server
      8. Save the sync log
     */

    FUNCTION_CALL_TRACE;

    if (!mContactBackend || !mGoogleAuth || !mParser || !mTransport)
        return false;

    LOG_DEBUG ("Init done. Continuing with sync");

    // syncStateChanged to signal changes from CONNECTING, RECEIVING
    // SENDING, DISCONNECTING, CLOSED
    connect(this, SIGNAL(stateChanged(Sync::SyncProgressDetail)),
            this, SLOT(receiveStateChanged(Sync::SyncProgressDetail)));

    // Take necessary action when sync is finished
    // FIXME: SyncStatus should reflect the status of the
    // transaction. More status fields need to be added
    connect(this, SIGNAL(syncFinished(Sync::SyncStatus)),
            this, SLOT(receiveSyncFinished(Sync::SyncStatus)));

    QTimer::singleShot (0, this, SLOT (start ()));
    return true;
}
示例#27
0
void RemoteSync::syncReply(WP::err code)
{
    if (code != WP::kOk)
        return;

    QByteArray data = fServerReply->readAll();
    fServerReply = NULL;

    IqInStanzaHandler iqHandler(kResult);
    SyncPullData syncPullData;
    SyncPullHandler *syncPullHandler = new SyncPullHandler(&syncPullData);
    iqHandler.addChildHandler(syncPullHandler);

    ProtocolInStream inStream(data);
    inStream.addHandler(&iqHandler);

    inStream.parse();

    QString localBranch = fDatabase->branch();
    QString localTipCommit = fDatabase->getTip();
    QString lastSyncCommit = fDatabase->getLastSyncCommit(fRemoteStorage->getUid(), localBranch);

    if (!syncPullHandler->hasBeenHandled() || syncPullData.branch != localBranch) {
        // error occured, the server should at least send back the branch name
        // TODO better error message
        emit syncFinished(WP::kBadValue);
        return;
    }
    if (syncPullData.tip == localTipCommit) {
        // done
        emit syncFinished(WP::kOk);
        return;
    }
    // see if the server is ahead by checking if we got packages
    if (syncPullData.pack.size() != 0) {
        fSyncUid = syncPullData.tip;
        WP::err error = fDatabase->importPack(syncPullData.pack, lastSyncCommit,
                                              syncPullData.tip);
        if (error != WP::kOk) {
            emit syncFinished(error);
            return;
        }

        localTipCommit = fDatabase->getTip();
        // done? otherwise it was a merge and we have to push our merge
        if (localTipCommit == lastSyncCommit) {
            emit syncFinished(WP::kOk);
            return;
        }
    }

    // we are ahead of the server: push changes to the server
    QByteArray pack;
    WP::err error = fDatabase->exportPack(pack, lastSyncCommit, localTipCommit, fSyncUid);
    if (error != WP::kOk) {
        emit syncFinished(error);
        return;
    }
    fSyncUid = localTipCommit;

    QByteArray outData;
    ProtocolOutStream outStream(&outData);

    IqOutStanza *iqStanza = new IqOutStanza(kSet);
    outStream.pushStanza(iqStanza);
    OutStanza *pushStanza = new OutStanza("sync_push");
    pushStanza->addAttribute("branch", localBranch);
    pushStanza->addAttribute("start_commit", syncPullData.tip);
    pushStanza->addAttribute("last_commit", localTipCommit);
    outStream.pushChildStanza(pushStanza);
    OutStanza *pushPackStanza = new OutStanza("pack");
    pushPackStanza->setText(pack.toBase64());
    outStream.pushChildStanza(pushPackStanza);

    outStream.flush();

    fServerReply = fRemoteConnection->send(outData);
    connect(fServerReply, SIGNAL(finished(WP::err)), this, SLOT(syncPushReply(WP::err)));
}
示例#28
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    EdamProtocol *edam = EdamProtocol::GetInstance();

    ui->setupUi(this);

    pdfCache * pdf = new pdfCache(this);

    CustomNetworkAccessManager *nm = new CustomNetworkAccessManager(ui->editor->page()->networkAccessManager(), this, pdf);
    edam->setCNAM(nm);
    ui->editor->page()->setNetworkAccessManager(nm);

    Speller::setSettings(new DBSpellSettings(this, ui->editor));

    ui->editor->setContextMenuPolicy(Qt::CustomContextMenu);
    ui->editor->load(QUrl("qrc:///html/noteajax.html"));

    jsB = new jsBridge(this, pdf);
    jsB->setWebView(ui->editor);
    enmlWritter = new enml2(this);

    connect(ui->editor->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject()));

    loaded = false;
    editingEnabled = false;


    tagsActions = new QActionGroup(this);
    newTag = new TagLabel(this);
    newTag->hide();
    ui->tagsBar->addWidget(newTag);

    appIcon = QIcon(":img/hippo64.png");

    trayIcon = NULL;

    bool sysTrayEnabled = sql::readSyncStatus("systemTray", true).toBool();

    if (QSystemTrayIcon::isSystemTrayAvailable() && sysTrayEnabled)
        enableSystemTrayIcon(true);

    connect(edam, SIGNAL(AuthenticateFailed()), this, SLOT(authentificationFailed()));
    connect(edam, SIGNAL(syncFinished()), this, SLOT(syncFinished()));
    connect(edam, SIGNAL(syncStarted(int)), this, SLOT(syncStarted(int)));
    connect(edam, SIGNAL(noteGuidChanged(QString,QString)), this, SLOT(changeNoteGuid(QString,QString)));
    connect(ui->notebooks, SIGNAL(itemSelectionChanged()), this, SLOT(switchNotebook()));
    connect(ui->tags, SIGNAL(itemSelectionChanged()), this, SLOT(switchTag()));
    connect(ui->tags, SIGNAL(tagAdded(QString,QString)), this, SLOT(addTag(QString,QString)));
    connect(ui->tags, SIGNAL(tagsUpdated()), this, SLOT(updateTagsToolBar()));
    connect(ui->tags, SIGNAL(tagsUpdated()), this, SLOT(switchTag()));
    connect(ui->NotesList, SIGNAL(noteSwitched()), this, SLOT(switchNote()));
    connect(ui->action_Abaut, SIGNAL(triggered()), this, SLOT(loadAboutInfo()));
    connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(closeWindow()));
    connect(ui->actionNew_Note, SIGNAL(triggered()), this, SLOT(newNote()));
    connect(ui->actionSync, SIGNAL(triggered()), this, SLOT(sync()));
    connect(ui->noteTitle, SIGNAL(textEdited(QString)), this, SLOT(noteTitleChange(QString)));
    connect(ui->actionAccount_info, SIGNAL(triggered()), this, SLOT(showUserInfo()));
    connect(ui->editor->page(), SIGNAL(linkClicked(QUrl)), this, SLOT(openURL(QUrl)));
    connect(ui->editor->page(), SIGNAL(microFocusChanged()), this, SLOT(updateEditButtonsState()));
    connect(ui->editor, SIGNAL(selectionChanged()), this, SLOT(updateSelectionButtonsState()));
    connect(ui->editor->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest)));
    connect(ui->editor, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(editorContextMenuRequested(QPoint)));
    connect(ui->editor, SIGNAL(fileInserted(QString)), this, SLOT(insertFile(QString)));
    connect(ui->notebooks, SIGNAL(noteMoved(QString,QString)), this, SLOT(moveNote(QString,QString)));
    connect(ui->notebooks, SIGNAL(noteDeleted(QString)), this, SLOT(deleteNote(QString)));
    connect(ui->notebooks, SIGNAL(noteRestored(QString,QString)), this, SLOT(restoreNote(QString,QString)));
    connect(ui->NotesList, SIGNAL(noteDeleted(QString)), this, SLOT(deleteNote(QString)));
    connect(ui->NotesList, SIGNAL(noteRestored(QString)), this, SLOT(restoreNote(QString)));
    connect(ui->NotesList, SIGNAL(noteCreated()), this, SLOT(newNote()));
    connect(ui->NotesList, SIGNAL(reloaded()), this, SLOT(updateCurrentNoteName()));
    connect(ui->editButton, SIGNAL(toggled(bool)), this, SLOT(setEditable(bool)));
    connect(ui->actionDelete_Note, SIGNAL(triggered()), this, SLOT(deleteNote()));
    connect(ui->toolBox, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int)));
    connect(ui->editor->page(), SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(linkHovered(QString,QString,QString)));
    connect(jsB, SIGNAL(hintMessage(QString,int)), ui->statusbar, SLOT(showMessage(QString,int)));
    connect(jsB, SIGNAL(noteChanged(QString)), this, SLOT(updateTagsToolBar(QString)));
    connect(jsB, SIGNAL(activeNoteSelectionChanged(bool)), ui->actionDelete_Note, SLOT(setEnabled(bool)));
    connect(jsB, SIGNAL(activeNoteSelectionChanged(bool)), ui->editButton, SLOT(setEnabled(bool)));
    connect(jsB, SIGNAL(editingStarted(bool)), ui->editButton, SLOT(setChecked(bool)));
    connect(jsB, SIGNAL(titleUpdated(QString,QString)), this, SLOT(updateNoteTitle(QString,QString)));
    connect(jsB, SIGNAL(conflictAdded(qint64,QString,bool)), this, SLOT(addConflict(qint64,QString,bool)));
    connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionNote_Info, SLOT(setEnabled(bool)));
    connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionExport, SLOT(setEnabled(bool)));
    connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionPrint, SLOT(setEnabled(bool)));
    connect(ui->editor, SIGNAL(tagUpdated(QString,bool)), this, SLOT(updateTag(QString,bool)));
    connect(tagsActions, SIGNAL(triggered(QAction*)), this, SLOT(tagClicked(QAction*)));
    connect(newTag, SIGNAL(tagCreated(QString)), this, SLOT(createTag(QString)));
    connect(ui->actionKeep_only_this_Version, SIGNAL(triggered()), this, SLOT(keepThisVersion()));
    connect(ui->actionNote_Info, SIGNAL(triggered()), this, SLOT(showNoteInfo()));
    connect(ui->actionExport, SIGNAL(triggered()), this, SLOT(exportNote()));
    connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print()));
    connect(this, SIGNAL(titleChanged(QString,QString)), jsB, SIGNAL(titleChanged(QString,QString)));


    setWindowIcon(appIcon);
    setWindowTitle("Hippo Notes");

    setTabOrder(ui->noteTitle, ui->editor);

    ui->notebooks->setSortingEnabled(true);
    ui->notebooks->sortByColumn(0, Qt::AscendingOrder);
    ui->editBar->setVisible(false);

    ui->mainToolBar->addAction(ui->actionNew_Note);
    ui->mainToolBar->addAction(ui->actionSync);

    QFontComboBox *font = new QFontComboBox(this);
    font->setDisabled(true);
    font->setFontFilters(QFontComboBox::ScalableFonts);
    font->setEditable(false);
    connect(this, SIGNAL(editButtonsStateChanged(bool)), font, SLOT(setEnabled(bool)));
    connect(this, SIGNAL(updateFont(QFont)), font, SLOT(setCurrentFont(QFont)));
    connect(font, SIGNAL(activated(QString)), this, SLOT(changeFont(QString)));
    ui->editBar->addWidget(font);

    QComboBox *fontSize = new QComboBox(this);
    fontSize->setDisabled(true);
    fontSize->setEditable(false);
    for (int i = 1; i <= 7; i++)
        fontSize->addItem(QString::number(i));
    connect(this, SIGNAL(editButtonsStateChanged(bool)), fontSize, SLOT(setEnabled(bool)));
    connect(this, SIGNAL(updateFontSize(int)), fontSize, SLOT(setCurrentIndex(int)));
    connect(fontSize, SIGNAL(activated(QString)), this, SLOT(changeFontSize(QString)));
    ui->editBar->addWidget(fontSize);

    QAction *boldIco = ui->editor->pageAction(QWebPage::ToggleBold);
    boldIco->setIcon(QIcon::fromTheme("format-text-bold"));
    ui->editBar->addAction(boldIco);

    QAction *italicIco = ui->editor->pageAction(QWebPage::ToggleItalic);
    italicIco->setIcon(QIcon::fromTheme("format-text-italic"));
    ui->editBar->addAction(italicIco);

    QAction *underlineIco = ui->editor->pageAction(QWebPage::ToggleUnderline);
    underlineIco->setIcon(QIcon::fromTheme("format-text-underline"));
    ui->editBar->addAction(underlineIco);

    QAction *strikethroughIco = ui->editor->pageAction(QWebPage::ToggleStrikethrough);
    strikethroughIco->setIcon(QIcon::fromTheme("format-text-strikethrough"));
    ui->editBar->addAction(strikethroughIco);

    ui->editBar->addSeparator();

    QAction *undoIco = ui->editor->pageAction(QWebPage::Undo);
    undoIco->setIcon(QIcon::fromTheme("edit-undo"));
    undoIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z));
    ui->editBar->addAction(undoIco);
    ui->menu_Edit->addAction(undoIco);

    QAction *redoIco = ui->editor->pageAction(QWebPage::Redo);
    redoIco->setIcon(QIcon::fromTheme("edit-redo"));
    redoIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z));
    ui->editBar->addAction(redoIco);
    ui->menu_Edit->addAction(redoIco);

    ui->editBar->addSeparator();

    QAction *rformatIco = ui->editor->pageAction(QWebPage::RemoveFormat);
    rformatIco->setIcon(QIcon::fromTheme("edit-clear"));
    ui->editBar->addAction(rformatIco);

    ui->editBar->addSeparator();

    QAction *leftIco = ui->editor->pageAction(QWebPage::AlignLeft);
    leftIco->setIcon(QIcon::fromTheme("format-justify-left"));
    ui->editBar->addAction(leftIco);

    QAction *centerIco = ui->editor->pageAction(QWebPage::AlignCenter);
    centerIco->setIcon(QIcon::fromTheme("format-justify-center"));
    ui->editBar->addAction(centerIco);

    QAction *rightIco = ui->editor->pageAction(QWebPage::AlignRight);
    rightIco->setIcon(QIcon::fromTheme("format-justify-right"));
    ui->editBar->addAction(rightIco);

    QAction *fillIco = ui->editor->pageAction(QWebPage::AlignJustified);
    fillIco->setIcon(QIcon::fromTheme("format-justify-fill"));
    ui->editBar->addAction(fillIco);

    ui->editBar->addSeparator();

    QAction *indentIco = ui->editor->pageAction(QWebPage::Indent);
    indentIco->setIcon(QIcon::fromTheme("format-indent-more"));
    ui->editBar->addAction(indentIco);

    QAction *outdentIco = ui->editor->pageAction(QWebPage::Outdent);
    outdentIco->setIcon(QIcon::fromTheme("format-indent-less"));
    ui->editBar->addAction(outdentIco);

    QAction *superscriptIco = ui->editor->pageAction(QWebPage::ToggleSuperscript);
    superscriptIco->setIcon(QIcon::fromTheme("format-text-superscript"));
    ui->editBar->addAction(superscriptIco);

    QAction *subscriptIco = ui->editor->pageAction(QWebPage::ToggleSubscript);
    subscriptIco->setIcon(QIcon::fromTheme("format-text-subscript"));
    ui->editBar->addAction(subscriptIco);

    QAction *unorderedIco = ui->editor->pageAction(QWebPage::InsertUnorderedList);
    unorderedIco->setIcon(QIcon::fromTheme("format-list-unordered"));
    ui->editBar->addAction(unorderedIco);

    QAction *orderedIco = ui->editor->pageAction(QWebPage::InsertOrderedList);
    orderedIco->setIcon(QIcon::fromTheme("format-list-ordered"));
    ui->editBar->addAction(orderedIco);

    QAction *lineIco = new QAction("Insert horizontal line", this);
    lineIco->setIcon(QIcon::fromTheme("insert-horizontal-rule"));
    lineIco->setDisabled(true);
    connect(this, SIGNAL(editButtonsStateChanged(bool)), lineIco, SLOT(setEnabled(bool)));
    connect(lineIco, SIGNAL(triggered()), this, SLOT(insertHorizontalLine()));
    ui->editBar->addAction(lineIco);

    ui->menu_Edit->addSeparator();

    QAction *cutIco = ui->editor->pageAction(QWebPage::Cut);
    cutIco->setIcon(QIcon::fromTheme("edit-cut"));
    cutIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X));
    ui->menu_Edit->addAction(cutIco);

    QAction *copyIco = ui->editor->pageAction(QWebPage::Copy);
    copyIco->setIcon(QIcon::fromTheme("edit-copy"));
    copyIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
    ui->menu_Edit->addAction(copyIco);

    QAction *pasteIco = ui->editor->pageAction(QWebPage::Paste);
    pasteIco->setIcon(QIcon::fromTheme("edit-paste"));
    pasteIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V));
    ui->menu_Edit->addAction(pasteIco);

    QAction *pasteSpecialIco = ui->editor->pageAction(QWebPage::PasteAndMatchStyle);
    pasteSpecialIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V));
    ui->menu_Edit->addAction(pasteSpecialIco);

    ui->menu_Edit->addSeparator();

    QAction *insertUrlIco = new QAction("Create link", this);
    insertUrlIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
    insertUrlIco->setDisabled(true);
    insertUrlIco->setIcon(QIcon::fromTheme("insert-link"));
    connect(this, SIGNAL(selectionButtonsStateChanged(bool)), insertUrlIco, SLOT(setDisabled(bool)));
    connect(insertUrlIco, SIGNAL(triggered()), this, SLOT(insertUrl()));
    ui->menu_Edit->addAction(insertUrlIco);

    QAction *todoIco = new QAction("Insert To-do Checkbox", this);
    todoIco->setIcon(QIcon::fromTheme("checkbox"));
    todoIco->setDisabled(true);
    connect(this, SIGNAL(editButtonsStateChanged(bool)), todoIco, SLOT(setEnabled(bool)));
    connect(todoIco, SIGNAL(triggered()), jsB, SIGNAL(insertToDo()));
    ui->menu_Edit->addAction(todoIco);

    QAction *insertImage = new QAction("Insert Image", this);
    insertImage->setIcon(QIcon::fromTheme("insert-image"));
    insertImage->setDisabled(true);
    connect(this, SIGNAL(editButtonsStateChanged(bool)), insertImage, SLOT(setEnabled(bool)));
    connect(insertImage, SIGNAL(triggered()), this, SLOT(insertImg()));
    ui->menu_Edit->addAction(insertImage);

    QAction *insertFile = new QAction("Insert File", this);
    insertFile->setDisabled(true);
    connect(this, SIGNAL(editButtonsStateChanged(bool)), insertFile, SLOT(setEnabled(bool)));
    connect(insertFile, SIGNAL(triggered()), this, SLOT(insertFile()));
    ui->menu_Edit->addAction(insertFile);

    QAction *encryptIco = new QAction("Encrypt Selected Text...", this);
    encryptIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_X));
    encryptIco->setDisabled(true);
    encryptIco->setIcon(QIcon::fromTheme("document-edit-encrypt"));
    connect(this, SIGNAL(selectionButtonsStateChanged(bool)), encryptIco, SLOT(setDisabled(bool)));
    connect(encryptIco, SIGNAL(triggered()), jsB, SIGNAL(encryptText()));
    ui->menu_Edit->addAction(encryptIco);

    ui->menu_Edit->addSeparator();

    QAction *options = new QAction("&Options...", this);
    options->setIcon(QIcon::fromTheme("preferences-other"));
    connect(options, SIGNAL(triggered()), this, SLOT(showOptions()));
    ui->menu_Edit->addAction(options);


    clearConflictBar();
    connect(jsB, SIGNAL(showConflict()), ui->conflictBar, SLOT(show()));
    connect(jsB, SIGNAL(showConflict()), ui->conflictBarBottom, SLOT(show()));

    conflictsGroup = new QActionGroup(this);
    connect(conflictsGroup, SIGNAL(triggered(QAction*)), this, SLOT(changeNoteVersion(QAction*)));

    searchIndex = new SearchIndex(this);
    connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(search()));
    connect(edam, SIGNAL(syncFinished()), searchIndex, SLOT(buildSearchIndex()));
    connect(jsB, SIGNAL(noteUpdated(QString)), searchIndex, SLOT(updateNoteIndex(QString)));
    connect(edam, SIGNAL(noteUpdated(QString)), searchIndex, SLOT(dropNoteIndex(QString)));
    connect(ui->searchInput, SIGNAL(returnPressed()), this, SLOT(search()));

    QByteArray mainWindowGeometry = sql::readSyncStatus("mainWindowGeometry").toString().toLatin1();
    if (!mainWindowGeometry.isEmpty())
        restoreGeometry(QByteArray::fromBase64(mainWindowGeometry));

    QByteArray mainWidgetsSplitterState = sql::readSyncStatus("mainWidgetsSplitterState").toString().toLatin1();
    if (!mainWidgetsSplitterState.isEmpty())
        ui->mainWidgetsSplitter->restoreState(QByteArray::fromBase64(mainWidgetsSplitterState));

    //showWindow();
    edam->init();
}
示例#29
0
文件: folder.cpp 项目: stonerl/client
void Folder::slotEmitFinishedDelayed()
{
    emit syncFinished( _syncResult );
}
示例#30
0
void GitFolder::startSync()
{
    QMutexLocker locker(&_syncMutex);
    emit syncStarted();
    emit syncFinished(SyncResult(SyncResult::Success));
}