Exemple #1
0
void AddFriendForm::onSendTriggered()
{
    QString id = toxId.text().trimmed();

    if (!ToxId::isToxId(id))
    {
        ToxId toxId = Toxme::lookup(id); // Try Toxme
        if (toxId.toString().isEmpty())
        {
            GUI::showWarning(tr("Couldn't add friend"),
                             tr("This Tox ID does not exist", "Toxme error"));
            return;
        }
        id = toxId.toString();
    }

    deleteFriendRequest(id);
    if (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper())
        GUI::showWarning(tr("Couldn't add friend"),
                         tr("You can't add yourself as a friend!",
                            "When trying to add your own Tox ID as friend"));
    else
        emit friendRequested(id, getMessage());

    this->toxId.clear();
    this->message.clear();
}
void FriendsWidget::onAddFriendButtonClicked()
{
    AddFriendDialog dialog(this);

    if (dialog.exec() == QDialog::Accepted) {
        addFriend(dialog.getUserId(), dialog.getUsername());
        emit friendRequested(dialog.getUserId(), dialog.getMessage());
    }
}
void AddFriendForm::onSendTriggered()
{
    QString id = toxId.text().trimmed();

    if (id.isEmpty()) {
        showWarning(tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to"));
    } else if (isToxId(id)) {
        emit friendRequested(id, getMessage());
        this->toxId.setText("");
        this->message.setText("");
    } else {
        id = id.replace("@", "._tox.");
        dns.setName(id);
        dns.lookup();
    }
}
void AddFriendForm::handleDnsLookup()
{
    const QString idKeyWord("id=");

    if (dns.error() == QDnsLookup::NotFoundError) {
        showWarning(tr("This address does not exist","The DNS gives the Tox ID associated to toxme.se addresses"));
        return;
    }
    else if (dns.error() != QDnsLookup::NoError) {
        showWarning(tr("Error while looking up DNS","The DNS gives the Tox ID associated to toxme.se addresses"));
        return;
    }

    const QList<QDnsTextRecord> textRecords = dns.textRecords();
    if (textRecords.length() != 1) {
        showWarning(tr("Unexpected number of text records", "Error with the DNS"));
        return;
    }

    const QList<QByteArray> textRecordValues = textRecords.first().values();
    if (textRecordValues.length() != 1) {
        showWarning(tr("Unexpected number of values in text record", "Error with the DNS"));
        return;
    }

    const QString entry(textRecordValues.first());
    int idx = entry.indexOf(idKeyWord);
    if (idx < 0) {
        showWarning(tr("The DNS lookup does not contain any Tox ID", "Error with the DNS"));
        return;
    }

    idx += idKeyWord.length();
    if (entry.length() < idx + static_cast<int>(TOX_ID_LENGTH)) {
        showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS"));
        return;
    }

    const QString friendAdress = entry.mid(idx, TOX_ID_LENGTH);
    if (!isToxId(friendAdress)) {
        showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS"));
        return;
    }

    // finally we got it
    emit friendRequested(friendAdress, getMessage());
}
Exemple #5
0
void AddFriendForm::onSendTriggered()
{
    QString id = toxId.text().trimmed();

    if (id.isEmpty()) {
        showWarning(tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to"));
    } else if (isToxId(id)) {
        if (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper())
            showWarning(tr("You can't add yourself as a friend!","When trying to add your own Tox ID as friend"));
        else
            emit friendRequested(id, getMessage());
        this->toxId.setText("");
        this->message.setText("");
    } else {
        id = id.replace("@", "._tox.");
        dns.setName(id);
        dns.lookup();
    }
}
Exemple #6
0
Widget::Widget(QWidget *parent)
    : QMainWindow(parent),
      ui(new Ui::MainWindow),
      activeChatroomWidget{nullptr}
{
    ui->setupUi(this);

    ui->statusbar->hide();
    ui->menubar->hide();

    //restore window state
    restoreGeometry(Settings::getInstance().getWindowGeometry());
    restoreState(Settings::getInstance().getWindowState());
    ui->mainSplitter->restoreState(Settings::getInstance().getSplitterState());

    if (Settings::getInstance().getUseNativeDecoration())
    {
        ui->titleBar->hide();
        this->layout()->setContentsMargins(0, 0, 0, 0);

        ui->friendList->setObjectName("friendList");
        ui->friendList->setStyleSheet(Style::get(":ui/friendList/friendList.css"));
    }
    else
    {
        this->setObjectName("activeWindow");
        this->setStyleSheet(Style::get(":ui/window/window.css"));
        ui->statusPanel->setStyleSheet(QString(""));
        ui->friendList->setStyleSheet(QString(""));

        ui->friendList->setObjectName("friendList");
        ui->friendList->setStyleSheet(Style::get(":ui/friendList/friendList.css"));

        ui->tbMenu->setIcon(QIcon(":ui/window/applicationIcon.png"));
        ui->pbMin->setObjectName("minimizeButton");
        ui->pbMax->setObjectName("maximizeButton");
        ui->pbClose->setObjectName("closeButton");

        setWindowFlags(Qt::CustomizeWindowHint);
        setWindowFlags(Qt::FramelessWindowHint);

        addAction(ui->actionClose);

        connect(ui->pbMin, SIGNAL(clicked()), this, SLOT(minimizeBtnClicked()));
        connect(ui->pbMax, SIGNAL(clicked()), this, SLOT(maximizeBtnClicked()));
        connect(ui->pbClose, SIGNAL(clicked()), this, SLOT(close()));

        m_titleMode = FullTitle;
        moveWidget = false;
        inResizeZone = false;
        allowToResize = false;
        resizeVerSup = false;
        resizeHorEsq = false;
        resizeDiagSupEsq = false;
        resizeDiagSupDer = false;

        if (isMaximized())
        {
            showMaximized();
            ui->pbMax->setObjectName("restoreButton");
        }
    }

    isWindowMinimized = 0;

    ui->mainContent->setLayout(new QVBoxLayout());
    ui->mainHead->setLayout(new QVBoxLayout());
    ui->mainHead->layout()->setMargin(0);
    ui->mainHead->layout()->setSpacing(0);

    contactListWidget = new FriendListWidget();
    ui->friendList->setWidget(contactListWidget);
    ui->friendList->setLayoutDirection(Qt::RightToLeft);

    ui->nameLabel->setEditable(true);
    ui->statusLabel->setEditable(true);

    // delay setting username and message until Core inits
    //ui->nameLabel->setText(core->getUsername());
    ui->nameLabel->setStyleSheet("QLabel { color : white; font-size: 11pt; font-weight:bold;}");
    //ui->statusLabel->setText(core->getStatusMessage());
    ui->statusLabel->setStyleSheet("QLabel { color : white; font-size: 8pt;}");

    ui->statusButton->setStyleSheet(Style::get(":/ui/statusButton/statusButton.css"));

    QMenu *statusButtonMenu = new QMenu(ui->statusButton);
    QAction* setStatusOnline = statusButtonMenu->addAction(Widget::tr("Online","Button to set your status to 'Online'"));
    setStatusOnline->setIcon(QIcon(":ui/statusButton/dot_online.png"));
    QAction* setStatusAway = statusButtonMenu->addAction(Widget::tr("Away","Button to set your status to 'Away'"));
    setStatusAway->setIcon(QIcon(":ui/statusButton/dot_idle.png"));
    QAction* setStatusBusy = statusButtonMenu->addAction(Widget::tr("Busy","Button to set your status to 'Busy'"));
    setStatusBusy->setIcon(QIcon(":ui/statusButton/dot_busy.png"));
    ui->statusButton->setMenu(statusButtonMenu);

    ui->titleBar->setMouseTracking(true);
    ui->LTitle->setMouseTracking(true);
    ui->tbMenu->setMouseTracking(true);
    ui->pbMin->setMouseTracking(true);
    ui->pbMax->setMouseTracking(true);
    ui->pbClose->setMouseTracking(true);
    ui->statusHead->setMouseTracking(true);

    //ui->friendList->viewport()->installEventFilter(this);

    // disable proportional scaling
    ui->mainSplitter->setStretchFactor(0,0);
    ui->mainSplitter->setStretchFactor(1,1);

    ui->statusButton->setObjectName("offline");
    ui->statusButton->style()->polish(ui->statusButton);

    camera = new Camera;
    settingsDialog = new SettingsDialog(this);

    // Disable some widgets until we're connected to the DHT
    ui->statusButton->setEnabled(false);

    qRegisterMetaType<Status>("Status");
    qRegisterMetaType<vpx_image>("vpx_image");
    qRegisterMetaType<uint8_t>("uint8_t");
    qRegisterMetaType<int32_t>("int32_t");
    qRegisterMetaType<int64_t>("int64_t");
    qRegisterMetaType<ToxFile>("ToxFile");
    qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");

    coreThread = new QThread(this);
    core = new Core(camera, coreThread);
    core->moveToThread(coreThread);
    connect(coreThread, &QThread::started, core, &Core::start);

    connect(core, &Core::connected, this, &Widget::onConnected);
    connect(core, &Core::disconnected, this, &Widget::onDisconnected);
    connect(core, &Core::failedToStart, this, &Widget::onFailedToStartCore);
    connect(core, &Core::statusSet, this, &Widget::onStatusSet);
    connect(core, &Core::usernameSet, this, &Widget::setUsername);
    connect(core, &Core::statusMessageSet, this, &Widget::setStatusMessage);
    connect(core, SIGNAL(fileDownloadFinished(const QString&)), &filesForm, SLOT(onFileDownloadComplete(const QString&)));
    connect(core, SIGNAL(fileUploadFinished(const QString&)), &filesForm, SLOT(onFileUploadComplete(const QString&)));
    connect(core, &Core::friendAdded, this, &Widget::addFriend);
    connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed);
    connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
    connect(core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged);
    connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
    connect(core, &Core::friendStatusMessageChanged, this, &Widget::onFriendStatusMessageChanged);
    connect(core, &Core::friendUsernameLoaded, this, &Widget::onFriendUsernameLoaded);
    connect(core, &Core::friendStatusMessageLoaded, this, &Widget::onFriendStatusMessageLoaded);
    connect(core, &Core::friendRequestReceived, this, &Widget::onFriendRequestReceived);
    connect(core, &Core::friendMessageReceived, this, &Widget::onFriendMessageReceived);
    connect(core, &Core::groupInviteReceived, this, &Widget::onGroupInviteReceived);
    connect(core, &Core::groupMessageReceived, this, &Widget::onGroupMessageReceived);
    connect(core, &Core::groupNamelistChanged, this, &Widget::onGroupNamelistChanged);
    connect(core, &Core::emptyGroupCreated, this, &Widget::onEmptyGroupCreated);

    connect(this, &Widget::statusSet, core, &Core::setStatus);
    connect(this, &Widget::friendRequested, core, &Core::requestFriendship);
    connect(this, &Widget::friendRequestAccepted, core, &Core::acceptFriendRequest);

    connect(ui->addButton, SIGNAL(clicked()), this, SLOT(onAddClicked()));
    connect(ui->groupButton, SIGNAL(clicked()), this, SLOT(onGroupClicked()));
    connect(ui->transferButton, SIGNAL(clicked()), this, SLOT(onTransferClicked()));
    connect(ui->settingsButton, SIGNAL(clicked()), this, SLOT(onSettingsClicked()));
    connect(ui->nameLabel, SIGNAL(textChanged(QString,QString)), this, SLOT(onUsernameChanged(QString,QString)));
    connect(ui->statusLabel, SIGNAL(textChanged(QString,QString)), this, SLOT(onStatusMessageChanged(QString,QString)));
    connect(setStatusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
    connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
    connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
    connect(&friendForm, SIGNAL(friendRequested(QString,QString)), this, SIGNAL(friendRequested(QString,QString)));

    coreThread->start();

    friendForm.show(*ui);
}
Exemple #7
0
void AddFriendForm::handleDnsLookup()
{
    const QString idKeyWord("id="), verKeyWord("v=");

    if (dns.error() == QDnsLookup::NotFoundError) {
        showWarning(tr("This address does not exist","The DNS gives the Tox ID associated to toxme.se addresses"));
        return;
    }
    else if (dns.error() != QDnsLookup::NoError) {
        showWarning(tr("Error while looking up DNS","The DNS gives the Tox ID associated to toxme.se addresses"));
        return;
    }

    const QList<QDnsTextRecord> textRecords = dns.textRecords();
    if (textRecords.length() != 1) {
        showWarning(tr("Unexpected number of text records", "Error with the DNS"));
        return;
    }

    const QList<QByteArray> textRecordValues = textRecords.first().values();
    if (textRecordValues.length() != 1) {
        showWarning(tr("Unexpected number of values in text record", "Error with the DNS"));
        return;
    }

    const QString entry(textRecordValues.first());

    // Check toxdns protocol version, we only support tox1 for now
    int verx = entry.indexOf(verKeyWord);
    if (verx) {
        verx += verKeyWord.size();
        int verend = entry.indexOf(';', verx);
        if (verend)
        {
            QString ver = entry.mid(verx, verend);
            if (ver != "tox1")
            {
                showWarning(tr("The version of Tox DNS used by this server is not supported", "Error with the DNS"));
                return;
            }
        }
    }

    int idx = entry.indexOf(idKeyWord);
    if (idx < 0) {
        showWarning(tr("The DNS lookup does not contain any Tox ID", "Error with the DNS"));
        return;
    }

    idx += idKeyWord.length();
    if (entry.length() < idx + static_cast<int>(TOX_ID_LENGTH)) {
        showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS"));
        return;
    }

    const QString friendAdress = entry.mid(idx, TOX_ID_LENGTH);
    if (!isToxId(friendAdress)) {
        showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS"));
        return;
    }

    // finally we got it
    emit friendRequested(friendAdress, getMessage());
    this->toxId.setText("");
    this->message.setText("");
}
Exemple #8
0
void Widget::init()
{
    ui->setupUi(this);
    
    if (QSystemTrayIcon::isSystemTrayAvailable())
    {
        icon = new QSystemTrayIcon(this);
        icon->setIcon(this->windowIcon());
        trayMenu = new QMenu;
        
        statusOnline = new QAction(tr("Online"), this);
        statusOnline->setIcon(QIcon(":ui/statusButton/dot_online.png"));
        connect(statusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
        statusAway = new QAction(tr("Away"), this);
        statusAway->setIcon(QIcon(":ui/statusButton/dot_idle.png"));
        connect(statusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
        statusBusy = new QAction(tr("Busy"), this);
        connect(statusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
        statusBusy->setIcon(QIcon(":ui/statusButton/dot_busy.png"));
        actionQuit = new QAction(tr("&Quit"), this);
        connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
        
        trayMenu->addAction(new QAction(tr("Change status to:"), this));
        trayMenu->addAction(statusOnline);
        trayMenu->addAction(statusAway);
        trayMenu->addAction(statusBusy);
        trayMenu->addSeparator();
        trayMenu->addAction(actionQuit);
        icon->setContextMenu(trayMenu);
        
        connect(icon,
                SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
                this,
                SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
        
        icon->show();
        
        if(Settings::getInstance().getAutostartInTray() == false)
            this->show();
    }
    else
    {
        qWarning() << "No system tray detected!";
        this->show();
    }

    ui->statusbar->hide();
    ui->menubar->hide();

    //restore window state
    restoreGeometry(Settings::getInstance().getWindowGeometry());
    restoreState(Settings::getInstance().getWindowState());
    ui->mainSplitter->restoreState(Settings::getInstance().getSplitterState());

    layout()->setContentsMargins(0, 0, 0, 0);
    ui->friendList->setStyleSheet(Style::getStylesheet(":ui/friendList/friendList.css"));

    profilePicture = new MaskablePixmapWidget(this, QSize(40, 40), ":/img/avatar_mask.png");
    profilePicture->setPixmap(QPixmap(":/img/contact_dark.png"));
    profilePicture->setClickable(true);
    ui->myProfile->insertWidget(0, profilePicture);
    ui->myProfile->insertSpacing(1, 7);

    ui->mainContent->setLayout(new QVBoxLayout());
    ui->mainHead->setLayout(new QVBoxLayout());
    ui->mainHead->layout()->setMargin(0);
    ui->mainHead->layout()->setSpacing(0);
    

    if(QStyleFactory::keys().contains(Settings::getInstance().getStyle())
            && Settings::getInstance().getStyle() != "None")
    {
        ui->mainHead->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
        ui->mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
    }
    
    ui->mainHead->setStyleSheet(Style::getStylesheet(":ui/settings/mainHead.css"));    
    ui->mainContent->setStyleSheet(Style::getStylesheet(":ui/settings/mainContent.css"));
    
    ui->statusHead->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css"));

    contactListWidget = new FriendListWidget();
    ui->friendList->setWidget(contactListWidget);
    ui->friendList->setLayoutDirection(Qt::RightToLeft);

    ui->nameLabel->setEditable(true);
    ui->statusLabel->setEditable(true);

    ui->statusPanel->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css"));

    QMenu *statusButtonMenu = new QMenu(ui->statusButton);
    QAction* setStatusOnline = statusButtonMenu->addAction(Widget::tr("Online","Button to set your status to 'Online'"));
    setStatusOnline->setIcon(QIcon(":ui/statusButton/dot_online.png"));
    QAction* setStatusAway = statusButtonMenu->addAction(Widget::tr("Away","Button to set your status to 'Away'"));
    setStatusAway->setIcon(QIcon(":ui/statusButton/dot_idle.png"));
    QAction* setStatusBusy = statusButtonMenu->addAction(Widget::tr("Busy","Button to set your status to 'Busy'"));
    setStatusBusy->setIcon(QIcon(":ui/statusButton/dot_busy.png"));
    ui->statusButton->setMenu(statusButtonMenu);

    // disable proportional scaling
    ui->mainSplitter->setStretchFactor(0,0);
    ui->mainSplitter->setStretchFactor(1,1);

    ui->statusButton->setProperty("status", "offline");
    Style::repolish(ui->statusButton);

    // Disable some widgets until we're connected to the DHT
    ui->statusButton->setEnabled(false);

    idleTimer = new QTimer();
    int mins = Settings::getInstance().getAutoAwayTime();
    if (mins > 0)
        idleTimer->start(mins * 1000*60);

    qRegisterMetaType<Status>("Status");
    qRegisterMetaType<vpx_image>("vpx_image");
    qRegisterMetaType<uint8_t>("uint8_t");
    qRegisterMetaType<uint16_t>("uint16_t");
    qRegisterMetaType<int32_t>("int32_t");
    qRegisterMetaType<int64_t>("int64_t");
    qRegisterMetaType<QPixmap>("QPixmap");
    qRegisterMetaType<ToxFile>("ToxFile");
    qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
    qRegisterMetaType<Core::PasswordType>("Core::PasswordType");

    QString profilePath = detectProfile();
    coreThread = new QThread(this);
    core = new Core(Camera::getInstance(), coreThread, profilePath);
    core->moveToThread(coreThread);
    connect(coreThread, &QThread::started, core, &Core::start);
    
    filesForm = new FilesForm();
    addFriendForm = new AddFriendForm;
    settingsWidget = new SettingsWidget();

    connect(core, &Core::connected, this, &Widget::onConnected);
    connect(core, &Core::disconnected, this, &Widget::onDisconnected);
    connect(core, &Core::failedToStart, this, &Widget::onFailedToStartCore);
    connect(core, &Core::badProxy, this, &Widget::onBadProxyCore);
    connect(core, &Core::statusSet, this, &Widget::onStatusSet);
    connect(core, &Core::usernameSet, this, &Widget::setUsername);
    connect(core, &Core::statusMessageSet, this, &Widget::setStatusMessage);
    connect(core, &Core::selfAvatarChanged, this, &Widget::onSelfAvatarLoaded);
    connect(core, SIGNAL(fileDownloadFinished(const QString&)), filesForm, SLOT(onFileDownloadComplete(const QString&)));
    connect(core, SIGNAL(fileUploadFinished(const QString&)), filesForm, SLOT(onFileUploadComplete(const QString&)));
    connect(core, &Core::friendAdded, this, &Widget::addFriend);
    connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed);
    connect(core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged);
    connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
    connect(core, &Core::friendStatusMessageChanged, this, &Widget::onFriendStatusMessageChanged);
    connect(core, &Core::friendRequestReceived, this, &Widget::onFriendRequestReceived);
    connect(core, &Core::friendMessageReceived, this, &Widget::onFriendMessageReceived);
    connect(core, &Core::groupInviteReceived, this, &Widget::onGroupInviteReceived);
    connect(core, &Core::groupMessageReceived, this, &Widget::onGroupMessageReceived);
    connect(core, &Core::groupNamelistChanged, this, &Widget::onGroupNamelistChanged);
    connect(core, &Core::emptyGroupCreated, this, &Widget::onEmptyGroupCreated);
    connect(core, &Core::avInvite, this, &Widget::playRingtone);
    connect(core, &Core::blockingClearContacts, this, &Widget::clearContactsList, Qt::BlockingQueuedConnection);
    connect(core, &Core::blockingGetPassword, this, &Widget::getPassword, Qt::BlockingQueuedConnection);

    connect(core, SIGNAL(messageSentResult(int,QString,int)), this, SLOT(onMessageSendResult(int,QString,int)));
    connect(core, SIGNAL(groupSentResult(int,QString,int)), this, SLOT(onGroupSendResult(int,QString,int)));

    connect(this, &Widget::statusSet, core, &Core::setStatus);
    connect(this, &Widget::friendRequested, core, &Core::requestFriendship);
    connect(this, &Widget::friendRequestAccepted, core, &Core::acceptFriendRequest);
    connect(this, &Widget::changeProfile, core, &Core::switchConfiguration);

    connect(ui->addButton, SIGNAL(clicked()), this, SLOT(onAddClicked()));
    connect(ui->groupButton, SIGNAL(clicked()), this, SLOT(onGroupClicked()));
    connect(ui->transferButton, SIGNAL(clicked()), this, SLOT(onTransferClicked()));
    connect(ui->settingsButton, SIGNAL(clicked()), this, SLOT(onSettingsClicked()));
    connect(ui->nameLabel, SIGNAL(textChanged(QString, QString)), this, SLOT(onUsernameChanged(QString, QString)));
    connect(ui->statusLabel, SIGNAL(textChanged(QString, QString)), this, SLOT(onStatusMessageChanged(QString, QString)));
    connect(profilePicture, SIGNAL(clicked()), this, SLOT(onAvatarClicked()));
    connect(setStatusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
    connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
    connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
    connect(addFriendForm, SIGNAL(friendRequested(QString, QString)), this, SIGNAL(friendRequested(QString, QString)));
    connect(idleTimer, &QTimer::timeout, this, &Widget::onUserAway);

    coreThread->start();

    addFriendForm->show(*ui);

#if (AUTOUPDATE_ENABLED)
    if (Settings::getInstance().getCheckUpdates())
        AutoUpdater::checkUpdatesAsyncInteractive();
#endif
}
Exemple #9
0
void Widget::init()
{
    ui->setupUi(this);

    timer = new QTimer();
    timer->start(1000);
    offlineMsgTimer = new QTimer();
    offlineMsgTimer->start(15000);

    //restore window state
    restoreGeometry(Settings::getInstance().getWindowGeometry());
    restoreState(Settings::getInstance().getWindowState());
    ui->mainSplitter->restoreState(Settings::getInstance().getSplitterState());

    statusOnline = new QAction(tr("Online", "Button to set your status to 'Online'"), this);
    statusOnline->setIcon(getStatusIcon(Status::Online, 10, 10));
    connect(statusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
    statusAway = new QAction(tr("Away", "Button to set your status to 'Away'"), this);
    statusAway->setIcon(getStatusIcon(Status::Away, 10, 10));
    connect(statusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
    statusBusy = new QAction(tr("Busy", "Button to set your status to 'Busy'"), this);
    statusBusy->setIcon(getStatusIcon(Status::Busy, 10, 10));
    connect(statusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));

    ui->statusbar->hide();
    ui->menubar->hide();

    layout()->setContentsMargins(0, 0, 0, 0);
    ui->friendList->setStyleSheet(Style::resolve(Style::getStylesheet(":ui/friendList/friendList.css")));

    profilePicture = new MaskablePixmapWidget(this, QSize(40, 40), ":/img/avatar_mask.svg");
    profilePicture->setPixmap(QPixmap(":/img/contact_dark.svg"));
    profilePicture->setClickable(true);
    ui->myProfile->insertWidget(0, profilePicture);
    ui->myProfile->insertSpacing(1, 7);

    ui->mainContent->setLayout(new QVBoxLayout());
    ui->mainHead->setLayout(new QVBoxLayout());
    ui->mainHead->layout()->setMargin(0);
    ui->mainHead->layout()->setSpacing(0);

    ui->tooliconsZone->setStyleSheet(Style::resolve("QPushButton{background-color:@themeDark;border:none;}QPushButton:hover{background-color:@themeMediumDark;border:none;}"));
    
    if (QStyleFactory::keys().contains(Settings::getInstance().getStyle())
            && Settings::getInstance().getStyle() != "None")
    {
        ui->mainHead->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
        ui->mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
    }
    
    ui->mainHead->setStyleSheet(Style::getStylesheet(":ui/settings/mainHead.css"));    
    ui->mainContent->setStyleSheet(Style::getStylesheet(":ui/settings/mainContent.css"));
    
    ui->statusHead->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css"));

    contactListWidget = new FriendListWidget(0, Settings::getInstance().getGroupchatPosition());
    ui->friendList->setWidget(contactListWidget);
    ui->friendList->setLayoutDirection(Qt::RightToLeft);

    ui->statusLabel->setEditable(true);

    ui->statusPanel->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css"));

    QMenu *statusButtonMenu = new QMenu(ui->statusButton);
    statusButtonMenu->addAction(statusOnline);
    statusButtonMenu->addAction(statusAway);
    statusButtonMenu->addAction(statusBusy);
    ui->statusButton->setMenu(statusButtonMenu);

    // disable proportional scaling
    ui->mainSplitter->setStretchFactor(0,0);
    ui->mainSplitter->setStretchFactor(1,1);

    onStatusSet(Status::Offline);

    // Disable some widgets until we're connected to the DHT
    ui->statusButton->setEnabled(false);

    Style::setThemeColor(Settings::getInstance().getThemeColor());
    reloadTheme();
    updateIcons();

    filesForm = new FilesForm();
    addFriendForm = new AddFriendForm;
    profileForm = new ProfileForm();
    settingsWidget = new SettingsWidget();

    Core* core = Nexus::getCore();
    connect(core, SIGNAL(fileDownloadFinished(const QString&)), filesForm, SLOT(onFileDownloadComplete(const QString&)));
    connect(core, SIGNAL(fileUploadFinished(const QString&)), filesForm, SLOT(onFileUploadComplete(const QString&)));
    connect(settingsWidget, &SettingsWidget::setShowSystemTray, this, &Widget::onSetShowSystemTray);
    connect(core, SIGNAL(selfAvatarChanged(QPixmap)), profileForm, SLOT(onSelfAvatarLoaded(QPixmap)));
    connect(ui->addButton, SIGNAL(clicked()), this, SLOT(onAddClicked()));
    connect(ui->groupButton, SIGNAL(clicked()), this, SLOT(onGroupClicked()));
    connect(ui->transferButton, SIGNAL(clicked()), this, SLOT(onTransferClicked()));
    connect(ui->settingsButton, SIGNAL(clicked()), this, SLOT(onSettingsClicked()));
    connect(profilePicture, &MaskablePixmapWidget::clicked, this, &Widget::showProfile);
    connect(ui->nameLabel, &CroppingLabel::clicked, this, &Widget::showProfile);
    connect(ui->statusLabel, SIGNAL(textChanged(QString, QString)), this, SLOT(onStatusMessageChanged(QString, QString)));
    connect(ui->mainSplitter, &QSplitter::splitterMoved, this, &Widget::onSplitterMoved);
    connect(addFriendForm, SIGNAL(friendRequested(QString, QString)), this, SIGNAL(friendRequested(QString, QString)));
    connect(timer, &QTimer::timeout, this, &Widget::onUserAwayCheck);
    connect(timer, &QTimer::timeout, this, &Widget::onEventIconTick);
    connect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon);
    connect(offlineMsgTimer, &QTimer::timeout, this, &Widget::processOfflineMsgs);

    addFriendForm->show(*ui);

    connect(settingsWidget, &SettingsWidget::groupchatPositionToggled, contactListWidget, &FriendListWidget::onGroupchatPositionChanged);
#if (AUTOUPDATE_ENABLED)
    if (Settings::getInstance().getCheckUpdates())
        AutoUpdater::checkUpdatesAsyncInteractive();
#endif
    if (!Settings::getInstance().getShowSystemTray())
        show();
}