FileBrowserDialog *FileBrowserManager::openOrActivateDialog(const Account &account, const ServerRepo &repo, const QString &path)
{
    FileBrowserDialog *dialog = getDialog(account, repo.id);
    QString fixed_path = path;
    if (!fixed_path.startsWith("/")) {
        fixed_path = "/" + fixed_path;
    }
    if (!fixed_path.endsWith("/")) {
        fixed_path += "/";
    }
    if (dialog == NULL) {
        dialog = new FileBrowserDialog(account, repo, fixed_path);
        QRect screen = QApplication::desktop()->screenGeometry();
        dialog->setAttribute(Qt::WA_DeleteOnClose, true);
        dialog->show();
        dialog->move(screen.center() - dialog->rect().center());
        dialogs_.push_back(dialog);
        connect(dialog, SIGNAL(aboutToClose()), this, SLOT(onAboutToClose()));
    } else if (!path.isEmpty()) {
        dialog->enterPath(fixed_path);
    }
    dialog->raise();
    dialog->activateWindow();
    return dialog;
}
void AbstractSocket::connectPrivateSignals()
{

    // Used to manage socket expiration timeout
    // Expiration delay is reinit when a bytes is writted
    connect(this, SIGNAL(bytesWritten(qint64)),
            this, SLOT(onBytesWritten(qint64)));

    // Used to manage socket expiration timeout
    // Expiration delay is reinit when data are available is read
    connect(this, SIGNAL(readyRead()),
            this, SLOT(onReadyRead()));

    // Those next signals are used as debug, for now
    connect(this, SIGNAL(connected()),
            this, SLOT(onConnected()));
    connect(this, SIGNAL(disconnected()),
            this, SLOT(onDisconnected()));
    connect(this, SIGNAL(error ( QAbstractSocket::SocketError)),
            this, SLOT(onError ( QAbstractSocket::SocketError)));
    connect(this, SIGNAL(hostFound ()),
            this, SLOT(onHostFound ()));
    connect(this, SIGNAL(proxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator *)),
            this, SLOT(onProxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator *)));
    connect(this, SIGNAL(stateChanged (QAbstractSocket::SocketState)),
            this, SLOT(onStateChanged (QAbstractSocket::SocketState)));
    connect(this, SIGNAL(aboutToClose()),
            this, SLOT(onAboutToClose()));
    connect(this, SIGNAL(readChannelFinished()),
            this, SLOT(onReadChannelFinished()));
}
FileBrowserDialog *FileBrowserManager::openOrActivateDialog(const Account &account, const ServerRepo &repo)
{
    FileBrowserDialog *dialog = getDialog(account, repo.id);
    if (dialog == NULL) {
        dialog = new FileBrowserDialog(account, repo, seafApplet->mainWindow());
        QRect screen = QApplication::desktop()->screenGeometry();
        dialog->setAttribute(Qt::WA_DeleteOnClose, true);
        dialog->show();
        dialog->move(screen.center() - dialog->rect().center());
        dialogs_.push_back(dialog);
        connect(dialog, SIGNAL(aboutToClose()), this, SLOT(onAboutToClose()));
    }
    dialog->raise();
    dialog->activateWindow();
    return dialog;
}