mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Remove Settings singleton
* Make main.cpp's toxSave free functions into a ToxSave class so that it can be given Settings on construction. * Add void* to IPC callbacks so that classes can get back to themselves.
This commit is contained in:
parent
61b3cb528a
commit
0c967725df
|
@ -41,8 +41,9 @@
|
|||
#define TIME_COL_WIDTH 90.0
|
||||
|
||||
|
||||
ChatMessage::ChatMessage(DocumentCache& documentCache_)
|
||||
ChatMessage::ChatMessage(DocumentCache& documentCache_, Settings& settings_)
|
||||
: documentCache{documentCache_}
|
||||
, settings{settings_}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -51,16 +52,17 @@ ChatMessage::~ChatMessage() = default;
|
|||
ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QString& rawMessage,
|
||||
MessageType type, bool isMe, MessageState state,
|
||||
const QDateTime& date, DocumentCache& documentCache,
|
||||
SmileyPack& smileyPack, bool colorizeName)
|
||||
SmileyPack& smileyPack, Settings& settings,
|
||||
bool colorizeName)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
|
||||
|
||||
QString text = rawMessage.toHtmlEscaped();
|
||||
QString senderText = sender;
|
||||
|
||||
auto textType = Text::NORMAL;
|
||||
// smileys
|
||||
if (Settings::getInstance().getUseEmoticons())
|
||||
if (settings.getUseEmoticons())
|
||||
text = smileyPack.smileyfied(text);
|
||||
|
||||
// quotes (green text)
|
||||
|
@ -68,7 +70,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
|
|||
text = TextFormatter::highlightURI(text);
|
||||
|
||||
// text styling
|
||||
Settings::StyleType styleType = Settings::getInstance().getStylePreference();
|
||||
Settings::StyleType styleType = settings.getStylePreference();
|
||||
if (styleType != Settings::StyleType::NONE) {
|
||||
text = TextFormatter::applyMarkdown(text, styleType == Settings::StyleType::WITH_CHARS);
|
||||
}
|
||||
|
@ -90,7 +92,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
|
|||
}
|
||||
|
||||
// Note: Eliding cannot be enabled for RichText items. (QTBUG-17207)
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
QFont baseFont = settings.getChatMessageFont();
|
||||
QFont authorFont = baseFont;
|
||||
if (isMe)
|
||||
authorFont.setBold(true);
|
||||
|
@ -110,25 +112,25 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
|
|||
}
|
||||
}
|
||||
|
||||
msg->addColumn(new Text(documentCache, senderText, authorFont, true, sender, textType, color),
|
||||
msg->addColumn(new Text(documentCache, settings, senderText, authorFont, true, sender, textType, color),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new Text(documentCache, text, baseFont, false, ((type == ACTION) && isMe)
|
||||
msg->addColumn(new Text(documentCache, settings, text, baseFont, false, ((type == ACTION) && isMe)
|
||||
? QString("%1 %2").arg(sender, rawMessage)
|
||||
: rawMessage),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize));
|
||||
|
||||
switch (state) {
|
||||
case MessageState::complete:
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(),
|
||||
baseFont, documentCache),
|
||||
msg->addColumn(new Timestamp(date, settings.getTimestampFormat(),
|
||||
baseFont, documentCache, settings),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
break;
|
||||
case MessageState::pending:
|
||||
msg->addColumn(new Spinner(Style::getImagePath("chatArea/spinner.svg"), QSize(16, 16), 360.0 / 1.6),
|
||||
msg->addColumn(new Spinner(Style::getImagePath("chatArea/spinner.svg", settings), QSize(16, 16), 360.0 / 1.6),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
break;
|
||||
case MessageState::broken:
|
||||
msg->addColumn(new Broken(Style::getImagePath("chatArea/error.svg"), QSize(16, 16)),
|
||||
msg->addColumn(new Broken(Style::getImagePath("chatArea/error.svg", settings), QSize(16, 16)),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
break;
|
||||
}
|
||||
|
@ -137,32 +139,32 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
|
|||
|
||||
ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage,
|
||||
SystemMessageType type, const QDateTime& date,
|
||||
DocumentCache& documentCache)
|
||||
DocumentCache& documentCache, Settings& settings)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
|
||||
QString text = rawMessage.toHtmlEscaped();
|
||||
|
||||
QString img;
|
||||
switch (type) {
|
||||
case INFO:
|
||||
img = Style::getImagePath("chatArea/info.svg");
|
||||
img = Style::getImagePath("chatArea/info.svg", settings);
|
||||
break;
|
||||
case ERROR:
|
||||
img = Style::getImagePath("chatArea/error.svg");
|
||||
img = Style::getImagePath("chatArea/error.svg", settings);
|
||||
break;
|
||||
case TYPING:
|
||||
img = Style::getImagePath("chatArea/typing.svg");
|
||||
img = Style::getImagePath("chatArea/typing.svg", settings);
|
||||
break;
|
||||
}
|
||||
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
QFont baseFont = settings.getChatMessageFont();
|
||||
|
||||
msg->addColumn(new Image(QSize(18, 18), img),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new Text(documentCache, "<b>" + text + "</b>", baseFont, false, text),
|
||||
msg->addColumn(new Text(documentCache, settings, "<b>" + text + "</b>", baseFont, false, text),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left));
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(),
|
||||
baseFont, documentCache),
|
||||
msg->addColumn(new Timestamp(date, settings.getTimestampFormat(),
|
||||
baseFont, documentCache, settings),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
|
||||
return msg;
|
||||
|
@ -170,31 +172,34 @@ ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage,
|
|||
|
||||
ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, CoreFile& coreFile,
|
||||
ToxFile file, bool isMe, const QDateTime& date,
|
||||
DocumentCache& documentCache)
|
||||
DocumentCache& documentCache,
|
||||
Settings& settings)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
|
||||
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
QFont baseFont = settings.getChatMessageFont();
|
||||
QFont authorFont = baseFont;
|
||||
if (isMe) {
|
||||
authorFont.setBold(true);
|
||||
}
|
||||
|
||||
msg->addColumn(new Text(documentCache, sender, authorFont, true),
|
||||
msg->addColumn(new Text(documentCache, settings, sender, authorFont, true),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new ChatLineContentProxy(new FileTransferWidget(nullptr, coreFile, file), 320, 0.6f),
|
||||
msg->addColumn(new ChatLineContentProxy(new FileTransferWidget(nullptr, coreFile, file, settings), 320, 0.6f),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize));
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(), baseFont, documentCache),
|
||||
msg->addColumn(new Timestamp(date, settings.getTimestampFormat(), baseFont,
|
||||
documentCache, settings),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCache)
|
||||
ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCache,
|
||||
Settings& settings)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
|
||||
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
QFont baseFont = settings.getChatMessageFont();
|
||||
|
||||
// Note: "[user]..." is just a placeholder. The actual text is set in
|
||||
// ChatForm::setFriendTyping()
|
||||
|
@ -203,9 +208,9 @@ ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCa
|
|||
// user received typing notifications constantly since contact came online.
|
||||
// This causes "[user]..." to be displayed in place of user nick, as long
|
||||
// as user will keep typing. Issue #1280
|
||||
msg->addColumn(new NotificationIcon(QSize(18, 18)),
|
||||
msg->addColumn(new NotificationIcon(settings, QSize(18, 18)),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new Text(documentCache, "[user]...", baseFont, false, ""),
|
||||
msg->addColumn(new Text(documentCache, settings, "[user]...", baseFont, false, ""),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left));
|
||||
|
||||
return msg;
|
||||
|
@ -219,14 +224,15 @@ ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCa
|
|||
*
|
||||
* @return created message
|
||||
*/
|
||||
ChatMessage::Ptr ChatMessage::createBusyNotification(DocumentCache& documentCache)
|
||||
ChatMessage::Ptr ChatMessage::createBusyNotification(DocumentCache& documentCache,
|
||||
Settings& settings)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
|
||||
QFont baseFont = settings.getChatMessageFont();
|
||||
baseFont.setPixelSize(baseFont.pixelSize() + 2);
|
||||
baseFont.setBold(true);
|
||||
|
||||
msg->addColumn(new Text(documentCache, QObject::tr("Reformatting text...", "Waiting for text to be reformatted"), baseFont, false, ""),
|
||||
msg->addColumn(new Text(documentCache, settings, QObject::tr("Reformatting text...", "Waiting for text to be reformatted"), baseFont, false, ""),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Center));
|
||||
|
||||
return msg;
|
||||
|
@ -234,15 +240,16 @@ ChatMessage::Ptr ChatMessage::createBusyNotification(DocumentCache& documentCach
|
|||
|
||||
void ChatMessage::markAsDelivered(const QDateTime& time)
|
||||
{
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
QFont baseFont = settings.getChatMessageFont();
|
||||
|
||||
// remove the spinner and replace it by $time
|
||||
replaceContent(2, new Timestamp(time, Settings::getInstance().getTimestampFormat(), baseFont, documentCache));
|
||||
replaceContent(2, new Timestamp(time, settings.getTimestampFormat(),
|
||||
baseFont, documentCache, settings));
|
||||
}
|
||||
|
||||
void ChatMessage::markAsBroken()
|
||||
{
|
||||
replaceContent(2, new Broken(Style::getImagePath("chatArea/error.svg"), QSize(16, 16)));
|
||||
replaceContent(2, new Broken(Style::getImagePath("chatArea/error.svg", settings), QSize(16, 16)));
|
||||
}
|
||||
|
||||
QString ChatMessage::toString() const
|
||||
|
|
|
@ -29,6 +29,7 @@ class CoreFile;
|
|||
class QGraphicsScene;
|
||||
class DocumentCache;
|
||||
class SmileyPack;
|
||||
class Settings;
|
||||
|
||||
class ChatMessage : public ChatLine
|
||||
{
|
||||
|
@ -49,7 +50,7 @@ public:
|
|||
ALERT,
|
||||
};
|
||||
|
||||
explicit ChatMessage(DocumentCache& documentCache);
|
||||
ChatMessage(DocumentCache&, Settings&);
|
||||
~ChatMessage();
|
||||
ChatMessage(const ChatMessage&) = default;
|
||||
ChatMessage(ChatMessage&&) = default;
|
||||
|
@ -57,14 +58,14 @@ public:
|
|||
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage,
|
||||
MessageType type, bool isMe, MessageState state,
|
||||
const QDateTime& date, DocumentCache&,
|
||||
SmileyPack& smileyPack, bool colorizeName = false);
|
||||
SmileyPack&, Settings&, bool colorizeName = false);
|
||||
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type,
|
||||
const QDateTime& date, DocumentCache&);
|
||||
const QDateTime& date, DocumentCache&, Settings&);
|
||||
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, CoreFile& coreFile,
|
||||
ToxFile file, bool isMe, const QDateTime& date,
|
||||
DocumentCache&);
|
||||
static ChatMessage::Ptr createTypingNotification(DocumentCache&);
|
||||
static ChatMessage::Ptr createBusyNotification(DocumentCache&);
|
||||
DocumentCache&, Settings&);
|
||||
static ChatMessage::Ptr createTypingNotification(DocumentCache&, Settings&);
|
||||
static ChatMessage::Ptr createBusyNotification(DocumentCache&, Settings&);
|
||||
|
||||
void markAsDelivered(const QDateTime& time);
|
||||
void markAsBroken();
|
||||
|
@ -81,4 +82,5 @@ protected:
|
|||
private:
|
||||
bool action = false;
|
||||
DocumentCache& documentCache;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -62,17 +62,16 @@ T clamp(T x, T min, T max)
|
|||
return x;
|
||||
}
|
||||
|
||||
ChatMessage::Ptr createDateMessage(QDateTime timestamp, DocumentCache& documentCache)
|
||||
ChatMessage::Ptr createDateMessage(QDateTime timestamp, DocumentCache& documentCache, Settings& settings)
|
||||
{
|
||||
const auto& s = Settings::getInstance();
|
||||
const auto date = timestamp.date();
|
||||
auto dateText = date.toString(s.getDateFormat());
|
||||
return ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime(), documentCache);
|
||||
auto dateText = date.toString(settings.getDateFormat());
|
||||
return ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime(), documentCache, settings);
|
||||
}
|
||||
|
||||
ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool colorizeNames,
|
||||
const ChatLogMessage& chatLogMessage, DocumentCache& documentCache,
|
||||
SmileyPack& smileyPack)
|
||||
SmileyPack& smileyPack, Settings& settings)
|
||||
{
|
||||
auto messageType = chatLogMessage.message.isAction ? ChatMessage::MessageType::ACTION
|
||||
: ChatMessage::MessageType::NORMAL;
|
||||
|
@ -90,12 +89,12 @@ ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool col
|
|||
const auto timestamp = chatLogMessage.message.timestamp;
|
||||
return ChatMessage::createChatMessage(displayName, chatLogMessage.message.content, messageType,
|
||||
isSelf, chatLogMessage.state, timestamp, documentCache,
|
||||
smileyPack, colorizeNames);
|
||||
smileyPack, settings, colorizeNames);
|
||||
}
|
||||
|
||||
void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeNames,
|
||||
const ChatLogMessage& chatLogMessage, ChatLine::Ptr& chatLine,
|
||||
DocumentCache& documentCache, SmileyPack& smileyPack)
|
||||
DocumentCache& documentCache, SmileyPack& smileyPack, Settings& settings)
|
||||
{
|
||||
// HACK: This is kind of gross, but there's not an easy way to fit this into
|
||||
// the existing architecture. This shouldn't ever fail since we should only
|
||||
|
@ -112,7 +111,7 @@ void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeName
|
|||
}
|
||||
} else {
|
||||
chatLine = createMessage(displayName, isSelf, colorizeNames, chatLogMessage,
|
||||
documentCache, smileyPack);
|
||||
documentCache, smileyPack, settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,13 +208,14 @@ ChatLogIdx clampedAdd(ChatLogIdx idx, int val, IChatLog& chatLog)
|
|||
|
||||
|
||||
ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& documentCache_,
|
||||
SmileyPack& smileyPack_, QWidget* parent)
|
||||
SmileyPack& smileyPack_, Settings& settings_, QWidget* parent)
|
||||
: QGraphicsView(parent)
|
||||
, chatLog(chatLog_)
|
||||
, core(core_)
|
||||
, chatLineStorage(new ChatLineStorage())
|
||||
, documentCache(documentCache_)
|
||||
, smileyPack{smileyPack_}
|
||||
, settings(settings_)
|
||||
{
|
||||
// Create the scene
|
||||
busyScene = new QGraphicsScene(this);
|
||||
|
@ -223,7 +223,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc
|
|||
scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
|
||||
setScene(scene);
|
||||
|
||||
busyNotification = ChatMessage::createBusyNotification(documentCache);
|
||||
busyNotification = ChatMessage::createBusyNotification(documentCache, settings);
|
||||
busyNotification->addToScene(busyScene);
|
||||
busyNotification->visibilityChanged(true);
|
||||
|
||||
|
@ -548,7 +548,7 @@ void ChatWidget::insertChatlines(std::map<ChatLogIdx, ChatLine::Ptr> chatLines)
|
|||
if (!chatLineStorage->contains(date)) {
|
||||
// If there is no dateline for the given date we need to insert it
|
||||
// above the line we'd like to insert.
|
||||
auto dateLine = createDateMessage(date, documentCache);
|
||||
auto dateLine = createDateMessage(date, documentCache, settings);
|
||||
chatLineStorage->insertDateLine(date, dateLine);
|
||||
dateLine->addToScene(scene);
|
||||
dateLine->visibilityChanged(false);
|
||||
|
@ -797,7 +797,7 @@ void ChatWidget::fontChanged(const QFont& font)
|
|||
|
||||
void ChatWidget::reloadTheme()
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet("chatArea/chatArea.css"));
|
||||
setStyleSheet(Style::getStylesheet("chatArea/chatArea.css", settings));
|
||||
setBackgroundBrush(QBrush(Style::getColor(Style::GroundBase), Qt::SolidPattern));
|
||||
selectionRectColor = Style::getColor(Style::SelectText);
|
||||
selGraphItem->setBrush(QBrush(selectionRectColor));
|
||||
|
@ -1400,7 +1400,7 @@ bool ChatWidget::isActiveFileTransfer(ChatLine::Ptr l)
|
|||
|
||||
void ChatWidget::setTypingNotification()
|
||||
{
|
||||
typingNotification = ChatMessage::createTypingNotification(documentCache);
|
||||
typingNotification = ChatMessage::createTypingNotification(documentCache, settings);
|
||||
typingNotification->visibilityChanged(true);
|
||||
typingNotification->setVisible(false);
|
||||
typingNotification->addToScene(scene);
|
||||
|
@ -1419,7 +1419,7 @@ void ChatWidget::renderItem(const ChatLogItem& item, bool hideName, bool coloriz
|
|||
const auto& chatLogMessage = item.getContentAsMessage();
|
||||
|
||||
renderMessageRaw(item.getDisplayName(), isSelf, colorizeNames_, chatLogMessage,
|
||||
chatMessage, documentCache, smileyPack);
|
||||
chatMessage, documentCache, smileyPack, settings);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1433,7 +1433,7 @@ void ChatWidget::renderItem(const ChatLogItem& item, bool hideName, bool coloriz
|
|||
|
||||
auto chatMessageType = getChatMessageType(systemMessage);
|
||||
chatMessage = ChatMessage::createChatInfoMessage(systemMessage.toString(),
|
||||
chatMessageType, QDateTime::currentDateTime(), documentCache);
|
||||
chatMessageType, QDateTime::currentDateTime(), documentCache, settings);
|
||||
// Ignore caller's decision to hide the name. We show the icon in the
|
||||
// slot of the sender's name so we always want it visible
|
||||
hideName = false;
|
||||
|
@ -1453,7 +1453,7 @@ void ChatWidget::renderFile(QString displayName, ToxFile file, bool isSelf, QDat
|
|||
CoreFile* coreFile = core.getCoreFile();
|
||||
assert(coreFile);
|
||||
chatMessage = ChatMessage::createFileTransferMessage(displayName, *coreFile,
|
||||
file, isSelf, timestamp, documentCache);
|
||||
file, isSelf, timestamp, documentCache, settings);
|
||||
} else {
|
||||
auto proxy = static_cast<ChatLineContentProxy*>(chatMessage->getContent(1));
|
||||
assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType);
|
||||
|
|
|
@ -35,6 +35,7 @@ class QTimer;
|
|||
class ChatLineContent;
|
||||
struct ToxFile;
|
||||
class SmileyPack;
|
||||
class Settings;
|
||||
|
||||
class ChatLineStorage;
|
||||
|
||||
|
@ -44,7 +45,7 @@ class ChatWidget : public QGraphicsView
|
|||
Q_OBJECT
|
||||
public:
|
||||
ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache&, SmileyPack&,
|
||||
QWidget* parent = nullptr);
|
||||
Settings&, QWidget* parent = nullptr);
|
||||
virtual ~ChatWidget();
|
||||
|
||||
void insertChatlines(std::map<ChatLogIdx, ChatLine::Ptr> chatLines);
|
||||
|
@ -218,4 +219,5 @@ private:
|
|||
std::vector<std::function<void(void)>> renderCompletionFns;
|
||||
DocumentCache& documentCache;
|
||||
SmileyPack& smileyPack;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -48,7 +48,8 @@
|
|||
// The rightButton is used to cancel a file transfer, or to open the directory a file was
|
||||
// downloaded to.
|
||||
|
||||
FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file)
|
||||
FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile,
|
||||
ToxFile file, Settings& settings_)
|
||||
: QWidget(parent)
|
||||
, coreFile{_coreFile}
|
||||
, ui(new Ui::FileTransferWidget)
|
||||
|
@ -57,6 +58,7 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, Tox
|
|||
, buttonColor(Style::getColor(Style::TransferWait))
|
||||
, buttonBackgroundColor(Style::getColor(Style::GroundBase))
|
||||
, active(true)
|
||||
, settings(settings_)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -158,7 +160,7 @@ void FileTransferWidget::setBackgroundColor(const QColor& c, bool whiteFont)
|
|||
|
||||
setProperty("fontColor", whiteFont ? "white" : "black");
|
||||
|
||||
setStyleSheet(Style::getStylesheet("fileTransferInstance/filetransferWidget.css"));
|
||||
setStyleSheet(Style::getStylesheet("fileTransferInstance/filetransferWidget.css", settings));
|
||||
Style::repolish(this);
|
||||
|
||||
update();
|
||||
|
@ -377,11 +379,11 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
|
|||
|
||||
switch (file.status) {
|
||||
case ToxFile::TRANSMITTING:
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg")));
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg", settings)));
|
||||
ui->leftButton->setObjectName("pause");
|
||||
ui->leftButton->setToolTip(tr("Pause transfer"));
|
||||
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg")));
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg", settings)));
|
||||
ui->rightButton->setObjectName("cancel");
|
||||
ui->rightButton->setToolTip(tr("Cancel transfer"));
|
||||
|
||||
|
@ -390,16 +392,16 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
|
|||
|
||||
case ToxFile::PAUSED:
|
||||
if (file.pauseStatus.localPaused()) {
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/arrow_white.svg")));
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/arrow_white.svg", settings)));
|
||||
ui->leftButton->setObjectName("resume");
|
||||
ui->leftButton->setToolTip(tr("Resume transfer"));
|
||||
} else {
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg")));
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg", settings)));
|
||||
ui->leftButton->setObjectName("pause");
|
||||
ui->leftButton->setToolTip(tr("Pause transfer"));
|
||||
}
|
||||
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg")));
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg", settings)));
|
||||
ui->rightButton->setObjectName("cancel");
|
||||
ui->rightButton->setToolTip(tr("Cancel transfer"));
|
||||
|
||||
|
@ -407,16 +409,16 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
|
|||
break;
|
||||
|
||||
case ToxFile::INITIALIZING:
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg")));
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg", settings)));
|
||||
ui->rightButton->setObjectName("cancel");
|
||||
ui->rightButton->setToolTip(tr("Cancel transfer"));
|
||||
|
||||
if (file.direction == ToxFile::SENDING) {
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg")));
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg", settings)));
|
||||
ui->leftButton->setObjectName("pause");
|
||||
ui->leftButton->setToolTip(tr("Pause transfer"));
|
||||
} else {
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg")));
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg", settings)));
|
||||
ui->leftButton->setObjectName("accept");
|
||||
ui->leftButton->setToolTip(tr("Accept transfer"));
|
||||
}
|
||||
|
@ -427,12 +429,12 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
|
|||
ui->rightButton->hide();
|
||||
break;
|
||||
case ToxFile::FINISHED:
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg")));
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg", settings)));
|
||||
ui->leftButton->setObjectName("ok");
|
||||
ui->leftButton->setToolTip(tr("Open file"));
|
||||
ui->leftButton->show();
|
||||
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/dir.svg")));
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/dir.svg", settings)));
|
||||
ui->rightButton->setObjectName("dir");
|
||||
ui->rightButton->setToolTip(tr("Open file directory"));
|
||||
ui->rightButton->show();
|
||||
|
@ -466,7 +468,7 @@ void FileTransferWidget::handleButton(QPushButton* btn)
|
|||
QString path =
|
||||
QFileDialog::getSaveFileName(Q_NULLPTR,
|
||||
tr("Save a file", "Title of the file saving dialog"),
|
||||
Settings::getInstance().getGlobalAutoAcceptDir() + "/"
|
||||
settings.getGlobalAutoAcceptDir() + "/"
|
||||
+ fileInfo.fileName);
|
||||
acceptTransfer(path);
|
||||
}
|
||||
|
|
|
@ -33,13 +33,14 @@ class FileTransferWidget;
|
|||
|
||||
class QVariantAnimation;
|
||||
class QPushButton;
|
||||
class Settings;
|
||||
|
||||
class FileTransferWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file);
|
||||
FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file, Settings&);
|
||||
virtual ~FileTransferWidget();
|
||||
bool isActive() const;
|
||||
void onFileTransferUpdate(ToxFile file);
|
||||
|
@ -88,5 +89,6 @@ private:
|
|||
bool active;
|
||||
QTime lastTransmissionUpdate;
|
||||
ToxFile::FileStatus lastStatus = ToxFile::INITIALIZING;
|
||||
Settings& settings;
|
||||
|
||||
};
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
|
||||
NotificationIcon::NotificationIcon(QSize Size)
|
||||
NotificationIcon::NotificationIcon(Settings& settings, QSize Size)
|
||||
: size(Size)
|
||||
{
|
||||
pmap = PixmapCache::getInstance().get(Style::getImagePath("chatArea/typing.svg"), size);
|
||||
pmap = PixmapCache::getInstance().get(Style::getImagePath("chatArea/typing.svg", settings), size);
|
||||
|
||||
// Timer for the animation, if the Widget is not redrawn, no paint events will
|
||||
// arrive and the timer will not be restarted, so this stops automatically
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
#include <QPixmap>
|
||||
#include <QTimer>
|
||||
|
||||
class Settings;
|
||||
|
||||
class NotificationIcon : public ChatLineContent
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NotificationIcon(QSize size);
|
||||
explicit NotificationIcon(Settings&, QSize size);
|
||||
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
|
||||
|
|
|
@ -31,16 +31,17 @@
|
|||
#include <QTextBlock>
|
||||
#include <QTextFragment>
|
||||
|
||||
Text::Text(DocumentCache& documentCache_, const QString& txt, const QFont& font,
|
||||
bool enableElide, const QString& rwText, const TextType& type,
|
||||
Text::Text(DocumentCache& documentCache_, Settings& settings_, const QString& txt,
|
||||
const QFont& font, bool enableElide, const QString& rwText, const TextType& type,
|
||||
const QColor& custom)
|
||||
: rawText(rwText)
|
||||
, elide(enableElide)
|
||||
, defFont(font)
|
||||
, defStyleSheet(Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), font))
|
||||
, defStyleSheet(Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), settings_, font))
|
||||
, textType(type)
|
||||
, customColor(custom)
|
||||
, documentCache(documentCache_)
|
||||
, settings{settings_}
|
||||
{
|
||||
color = textColor();
|
||||
setText(txt);
|
||||
|
@ -251,7 +252,7 @@ void Text::visibilityChanged(bool visible)
|
|||
|
||||
void Text::reloadTheme()
|
||||
{
|
||||
defStyleSheet = Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), defFont);
|
||||
defStyleSheet = Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), settings, defFont);
|
||||
color = textColor();
|
||||
dirty = true;
|
||||
regenerate();
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
class QTextDocument;
|
||||
class DocumentCache;
|
||||
class Settings;
|
||||
|
||||
class Text : public ChatLineContent
|
||||
{
|
||||
|
@ -39,7 +40,7 @@ public:
|
|||
CUSTOM
|
||||
};
|
||||
|
||||
Text(DocumentCache&, const QString& txt = "", const QFont& font = QFont(),
|
||||
Text(DocumentCache&, Settings&, const QString& txt = "", const QFont& font = QFont(),
|
||||
bool enableElide = false, const QString& rawText = QString(),
|
||||
const TextType& type = NORMAL,
|
||||
const QColor& custom = Style::getColor(Style::MainText));
|
||||
|
@ -113,4 +114,5 @@ private:
|
|||
QColor color;
|
||||
QColor customColor;
|
||||
DocumentCache& documentCache;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
|
||||
#include "timestamp.h"
|
||||
|
||||
Timestamp::Timestamp(const QDateTime& time_, const QString& format, const QFont& font, DocumentCache& documentCache_)
|
||||
: Text(documentCache_, time_.toString(format), font, false, time_.toString(format))
|
||||
Timestamp::Timestamp(const QDateTime& time_, const QString& format,
|
||||
const QFont& font, DocumentCache& documentCache_, Settings& settings_)
|
||||
: Text(documentCache_, settings_, time_.toString(format), font, false,
|
||||
time_.toString(format))
|
||||
{
|
||||
time = time_;
|
||||
}
|
||||
|
|
|
@ -25,13 +25,14 @@
|
|||
|
||||
class QTextDocument;
|
||||
class DocumentCache;
|
||||
class Settings;
|
||||
|
||||
class Timestamp : public Text
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Timestamp(const QDateTime& time_, const QString& format, const QFont& font,
|
||||
DocumentCache&);
|
||||
DocumentCache&, Settings&);
|
||||
QDateTime getTime();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -26,9 +26,11 @@
|
|||
#include <QIcon>
|
||||
#include <QUrl>
|
||||
|
||||
CustomTextDocument::CustomTextDocument(SmileyPack& smileyPack_, QObject* parent)
|
||||
CustomTextDocument::CustomTextDocument(SmileyPack& smileyPack_,
|
||||
Settings& settings_, QObject* parent)
|
||||
: QTextDocument(parent)
|
||||
, smileyPack(smileyPack_)
|
||||
, settings(settings_)
|
||||
{
|
||||
setUndoRedoEnabled(false);
|
||||
setUseDesignMetrics(false);
|
||||
|
@ -37,8 +39,8 @@ CustomTextDocument::CustomTextDocument(SmileyPack& smileyPack_, QObject* parent)
|
|||
QVariant CustomTextDocument::loadResource(int type, const QUrl& name)
|
||||
{
|
||||
if (type == QTextDocument::ImageResource && name.scheme() == "key") {
|
||||
QSize size = QSize(Settings::getInstance().getEmojiFontPointSize(),
|
||||
Settings::getInstance().getEmojiFontPointSize());
|
||||
QSize size = QSize(settings.getEmojiFontPointSize(),
|
||||
settings.getEmojiFontPointSize());
|
||||
QString fileName = QUrl::fromPercentEncoding(name.toEncoded()).mid(4).toHtmlEscaped();
|
||||
|
||||
std::shared_ptr<QIcon> icon = smileyPack.getAsIcon(fileName);
|
||||
|
|
|
@ -26,12 +26,13 @@
|
|||
|
||||
class QIcon;
|
||||
class SmileyPack;
|
||||
class Settings;
|
||||
|
||||
class CustomTextDocument : public QTextDocument
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CustomTextDocument(SmileyPack&, QObject* parent = nullptr);
|
||||
CustomTextDocument(SmileyPack&, Settings&, QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual QVariant loadResource(int type, const QUrl& name);
|
||||
|
@ -39,4 +40,5 @@ protected:
|
|||
private:
|
||||
QList<std::shared_ptr<QIcon>> emoticonIcons;
|
||||
SmileyPack& smileyPack;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
#include "documentcache.h"
|
||||
#include "customtextdocument.h"
|
||||
|
||||
DocumentCache::DocumentCache(SmileyPack& smileyPack_)
|
||||
DocumentCache::DocumentCache(SmileyPack& smileyPack_, Settings& settings_)
|
||||
: smileyPack{smileyPack_}
|
||||
, settings{settings_}
|
||||
{
|
||||
}
|
||||
DocumentCache::~DocumentCache()
|
||||
|
@ -33,7 +34,7 @@ DocumentCache::~DocumentCache()
|
|||
QTextDocument* DocumentCache::pop()
|
||||
{
|
||||
if (documents.empty())
|
||||
documents.push(new CustomTextDocument(smileyPack));
|
||||
documents.push(new CustomTextDocument(smileyPack, settings));
|
||||
|
||||
return documents.pop();
|
||||
}
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
|
||||
class QTextDocument;
|
||||
class SmileyPack;
|
||||
class Settings;
|
||||
|
||||
class DocumentCache
|
||||
{
|
||||
public:
|
||||
explicit DocumentCache(SmileyPack& smileyPack);
|
||||
DocumentCache(SmileyPack&, Settings&);
|
||||
~DocumentCache();
|
||||
DocumentCache(DocumentCache&) = delete;
|
||||
DocumentCache& operator=(const DocumentCache&) = delete;
|
||||
|
@ -37,4 +38,5 @@ public:
|
|||
private:
|
||||
QStack<QTextDocument*> documents;
|
||||
SmileyPack& smileyPack;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -29,14 +29,14 @@
|
|||
QHash<ToxPk, Friend*> FriendList::friendList;
|
||||
QHash<uint32_t, ToxPk> FriendList::id2key;
|
||||
|
||||
Friend* FriendList::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
||||
Friend* FriendList::addFriend(uint32_t friendId, const ToxPk& friendPk, Settings& settings)
|
||||
{
|
||||
auto friendChecker = friendList.find(friendPk);
|
||||
if (friendChecker != friendList.end()) {
|
||||
qWarning() << "addFriend: friendPk already taken";
|
||||
}
|
||||
|
||||
QString alias = Settings::getInstance().getFriendAlias(friendPk);
|
||||
QString alias = settings.getFriendAlias(friendPk);
|
||||
Friend* newfriend = new Friend(friendId, friendPk, alias);
|
||||
friendList[friendPk] = newfriend;
|
||||
id2key[friendId] = friendPk;
|
||||
|
@ -59,12 +59,12 @@ const ToxPk& FriendList::id2Key(uint32_t friendId)
|
|||
return id2key[friendId];
|
||||
}
|
||||
|
||||
void FriendList::removeFriend(const ToxPk& friendPk, bool fake)
|
||||
void FriendList::removeFriend(const ToxPk& friendPk, Settings& settings, bool fake)
|
||||
{
|
||||
auto f_it = friendList.find(friendPk);
|
||||
if (f_it != friendList.end()) {
|
||||
if (!fake)
|
||||
Settings::getInstance().removeFriendSettings(f_it.value()->getPublicKey());
|
||||
settings.removeFriendSettings(f_it.value()->getPublicKey());
|
||||
friendList.erase(f_it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,15 +29,16 @@ class Friend;
|
|||
class QByteArray;
|
||||
class QString;
|
||||
class ToxPk;
|
||||
class Settings;
|
||||
|
||||
class FriendList
|
||||
{
|
||||
public:
|
||||
static Friend* addFriend(uint32_t friendId, const ToxPk& friendPk);
|
||||
static Friend* addFriend(uint32_t friendId, const ToxPk& friendPk, Settings&);
|
||||
static Friend* findFriend(const ToxPk& friendPk);
|
||||
static const ToxPk& id2Key(uint32_t friendId);
|
||||
static QList<Friend*> getAllFriends();
|
||||
static void removeFriend(const ToxPk& friendPk, bool fake = false);
|
||||
static void removeFriend(const ToxPk& friendPk, Settings&, bool fake = false);
|
||||
static void clear();
|
||||
static QString decideNickname(const ToxPk& friendPk, const QString& origName);
|
||||
|
||||
|
|
10
src/ipc.cpp
10
src/ipc.cpp
|
@ -189,9 +189,9 @@ bool IPC::isCurrentOwner()
|
|||
* @brief Register a handler for an IPC event
|
||||
* @param handler The handler callback. Should not block for more than a second, at worst
|
||||
*/
|
||||
void IPC::registerEventHandler(const QString& name, IPCEventHandler handler)
|
||||
void IPC::registerEventHandler(const QString& name, IPCEventHandler handler, void* userData)
|
||||
{
|
||||
eventHandlers[name] = handler;
|
||||
eventHandlers[name] = {handler, userData};
|
||||
}
|
||||
|
||||
bool IPC::isEventAccepted(time_t time)
|
||||
|
@ -269,11 +269,11 @@ IPC::IPCEvent* IPC::fetchEvent()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool IPC::runEventHandler(IPCEventHandler handler, const QByteArray& arg)
|
||||
bool IPC::runEventHandler(IPCEventHandler handler, const QByteArray& arg, void* userData)
|
||||
{
|
||||
bool result = false;
|
||||
if (QThread::currentThread() == qApp->thread()) {
|
||||
result = handler(arg);
|
||||
result = handler(arg, userData);
|
||||
} else {
|
||||
QMetaObject::invokeMethod(this, "runEventHandler", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(bool, result), Q_ARG(IPCEventHandler, handler),
|
||||
|
@ -313,7 +313,7 @@ void IPC::processEvents()
|
|||
QString name = QString::fromUtf8(evt->name);
|
||||
auto it = eventHandlers.find(name);
|
||||
if (it != eventHandlers.end()) {
|
||||
evt->accepted = runEventHandler(it.value(), evt->data);
|
||||
evt->accepted = runEventHandler(it.value().handler, evt->data, it.value().userData);
|
||||
qDebug() << "Processed event:" << name << "posted:" << evt->posted
|
||||
<< "accepted:" << evt->accepted;
|
||||
if (evt->dest == 0) {
|
||||
|
|
13
src/ipc.h
13
src/ipc.h
|
@ -27,7 +27,7 @@
|
|||
#include <ctime>
|
||||
#include <functional>
|
||||
|
||||
using IPCEventHandler = std::function<bool(const QByteArray&)>;
|
||||
using IPCEventHandler = std::function<bool(const QByteArray&, void*)>;
|
||||
|
||||
#define IPC_PROTOCOL_VERSION "2"
|
||||
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
time_t postEvent(const QString& name, const QByteArray& data = QByteArray(), uint32_t dest = 0);
|
||||
bool isCurrentOwner();
|
||||
void registerEventHandler(const QString& name, IPCEventHandler handler);
|
||||
void registerEventHandler(const QString& name, IPCEventHandler handler, void* userData);
|
||||
bool isEventAccepted(time_t time);
|
||||
bool waitUntilAccepted(time_t time, int32_t timeout = -1);
|
||||
bool isAttached() const;
|
||||
|
@ -78,15 +78,20 @@ public slots:
|
|||
|
||||
private:
|
||||
IPCMemory* global();
|
||||
bool runEventHandler(IPCEventHandler handler, const QByteArray& arg);
|
||||
bool runEventHandler(IPCEventHandler handler, const QByteArray& arg, void* userData);
|
||||
IPCEvent* fetchEvent();
|
||||
void processEvents();
|
||||
bool isCurrentOwnerNoLock();
|
||||
|
||||
private:
|
||||
struct Callback
|
||||
{
|
||||
IPCEventHandler handler;
|
||||
void* userData;
|
||||
};
|
||||
QTimer timer;
|
||||
uint64_t globalId;
|
||||
uint32_t profileId;
|
||||
QSharedMemory globalMemory;
|
||||
QMap<QString, IPCEventHandler> eventHandlers;
|
||||
QMap<QString, Callback> eventHandlers;
|
||||
};
|
||||
|
|
51
src/main.cpp
51
src/main.cpp
|
@ -55,19 +55,23 @@ QList<QByteArray>* logBuffer =
|
|||
QMutex* logBufferMutex = new QMutex();
|
||||
#endif
|
||||
|
||||
std::unique_ptr<Settings> settings;
|
||||
std::unique_ptr<ToxSave> toxSave;
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
// force save early even though destruction saves, because Windows OS will
|
||||
// close qTox before cleanup() is finished if logging out or shutting down,
|
||||
// once the top level window has exited, which occurs in ~Widget within
|
||||
// ~Nexus. Re-ordering Nexus destruction is not trivial.
|
||||
auto& s = Settings::getInstance();
|
||||
s.saveGlobal();
|
||||
s.savePersonal();
|
||||
s.sync();
|
||||
if (settings) {
|
||||
settings->saveGlobal();
|
||||
settings->savePersonal();
|
||||
settings->sync();
|
||||
}
|
||||
|
||||
Nexus::destroyInstance();
|
||||
Settings::destroyInstance();
|
||||
settings.reset();
|
||||
qDebug() << "Cleanup success";
|
||||
|
||||
#ifdef LOG_TO_FILE
|
||||
|
@ -183,8 +187,9 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt
|
|||
|
||||
std::unique_ptr<ToxURIDialog> uriDialog;
|
||||
|
||||
bool toxURIEventHandler(const QByteArray& eventData)
|
||||
bool toxURIEventHandler(const QByteArray& eventData, void* userData)
|
||||
{
|
||||
std::ignore = userData;
|
||||
if (!eventData.startsWith("tox:")) {
|
||||
return false;
|
||||
}
|
||||
|
@ -196,7 +201,8 @@ bool toxURIEventHandler(const QByteArray& eventData)
|
|||
uriDialog->handleToxURI(eventData);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -230,8 +236,9 @@ int main(int argc, char* argv[])
|
|||
qWarning() << "Couldn't load font";
|
||||
}
|
||||
|
||||
Settings& settings = Settings::getInstance();
|
||||
QString locale = settings.getTranslation();
|
||||
settings = std::unique_ptr<Settings>(new Settings());
|
||||
|
||||
QString locale = settings->getTranslation();
|
||||
// We need to init the resources in the translations_library explicitely.
|
||||
// See https://doc.qt.io/qt-5/resources.html#using-resources-in-a-library
|
||||
Q_INIT_RESOURCE(translations);
|
||||
|
@ -272,10 +279,10 @@ int main(int argc, char* argv[])
|
|||
QObject::tr("(SOCKS5/HTTP/NONE):(ADDRESS):(PORT)")));
|
||||
parser.process(*a);
|
||||
|
||||
uint32_t profileId = settings.getCurrentProfileId();
|
||||
uint32_t profileId = settings->getCurrentProfileId();
|
||||
IPC ipc(profileId);
|
||||
if (ipc.isAttached()) {
|
||||
QObject::connect(&settings, &Settings::currentProfileIdChanged, &ipc, &IPC::setProfileId);
|
||||
QObject::connect(settings.get(), &Settings::currentProfileIdChanged, &ipc, &IPC::setProfileId);
|
||||
} else {
|
||||
qWarning() << "Can't init IPC, maybe we're in a jail? Continuing with reduced multi-client functionality.";
|
||||
}
|
||||
|
@ -287,7 +294,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
#ifdef LOG_TO_FILE
|
||||
QString logFileDir = settings.getPaths().getAppCacheDirPath();
|
||||
QString logFileDir = settings->getPaths().getAppCacheDirPath();
|
||||
QDir(logFileDir).mkpath(".");
|
||||
|
||||
QString logfile = logFileDir + "qtox.log";
|
||||
|
@ -333,14 +340,14 @@ int main(int argc, char* argv[])
|
|||
qDebug() << "commit: " << GIT_VERSION;
|
||||
|
||||
QString profileName;
|
||||
bool autoLogin = settings.getAutoLogin();
|
||||
bool autoLogin = settings->getAutoLogin();
|
||||
|
||||
uint32_t ipcDest = 0;
|
||||
bool doIpc = ipc.isAttached();
|
||||
QString eventType, firstParam;
|
||||
if (parser.isSet("p")) {
|
||||
profileName = parser.value("p");
|
||||
if (!Profile::exists(profileName)) {
|
||||
if (!Profile::exists(profileName, settings->getPaths())) {
|
||||
qWarning() << "-p profile" << profileName + ".tox"
|
||||
<< "doesn't exist, opening login screen";
|
||||
doIpc = false;
|
||||
|
@ -353,7 +360,7 @@ int main(int argc, char* argv[])
|
|||
doIpc = false;
|
||||
autoLogin = false;
|
||||
} else {
|
||||
profileName = settings.getCurrentProfile();
|
||||
profileName = settings->getCurrentProfile();
|
||||
}
|
||||
|
||||
if (parser.positionalArguments().empty()) {
|
||||
|
@ -398,14 +405,14 @@ int main(int argc, char* argv[])
|
|||
// TODO(kriby): Consider moving application initializing variables into a globalSettings object
|
||||
// note: Because Settings is shouldering global settings as well as model specific ones it
|
||||
// cannot be integrated into a central model object yet
|
||||
nexus.setSettings(&settings);
|
||||
nexus.setSettings(settings.get());
|
||||
auto& cameraSource = Nexus::getCameraSource();
|
||||
// Autologin
|
||||
// TODO (kriby): Shift responsibility of linking views to model objects from nexus
|
||||
// Further: generate view instances separately (loginScreen, mainGUI, audio)
|
||||
Profile* profile = nullptr;
|
||||
if (autoLogin && Profile::exists(profileName) && !Profile::isEncrypted(profileName)) {
|
||||
profile = Profile::loadProfile(profileName, QString(), settings, &parser, cameraSource);
|
||||
if (autoLogin && Profile::exists(profileName, settings->getPaths()) && !Profile::isEncrypted(profileName, settings->getPaths())) {
|
||||
profile = Profile::loadProfile(profileName, QString(), *settings, &parser, cameraSource);
|
||||
if (!profile) {
|
||||
QMessageBox::information(nullptr, QObject::tr("Error"),
|
||||
QObject::tr("Failed to load profile automatically."));
|
||||
|
@ -426,16 +433,16 @@ int main(int argc, char* argv[])
|
|||
|
||||
if (ipc.isAttached()) {
|
||||
// Start to accept Inter-process communication
|
||||
ipc.registerEventHandler("uri", &toxURIEventHandler);
|
||||
ipc.registerEventHandler("save", &toxSaveEventHandler);
|
||||
ipc.registerEventHandler("activate", &toxActivateEventHandler);
|
||||
ipc.registerEventHandler("uri", &toxURIEventHandler, uriDialog.get());
|
||||
ipc.registerEventHandler("save", &ToxSave::toxSaveEventHandler, toxSave.get());
|
||||
ipc.registerEventHandler("activate", &toxActivateEventHandler, nullptr);
|
||||
}
|
||||
|
||||
// Event was not handled by already running instance therefore we handle it ourselves
|
||||
if (eventType == "uri") {
|
||||
uriDialog->handleToxURI(firstParam.toUtf8());
|
||||
} else if (eventType == "save") {
|
||||
handleToxSave(firstParam.toUtf8());
|
||||
toxSave->handleToxSave(firstParam.toUtf8());
|
||||
}
|
||||
|
||||
QObject::connect(a.get(), &QApplication::aboutToQuit, cleanup);
|
||||
|
|
|
@ -42,10 +42,11 @@ QString getShortName(const QString& name)
|
|||
|
||||
}
|
||||
|
||||
FriendChatroom::FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_)
|
||||
FriendChatroom::FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_, Settings& settings_)
|
||||
: frnd{frnd_}
|
||||
, dialogsManager{dialogsManager_}
|
||||
, core{core_}
|
||||
, settings{settings_}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -74,13 +75,13 @@ bool FriendChatroom::canBeInvited() const
|
|||
|
||||
int FriendChatroom::getCircleId() const
|
||||
{
|
||||
return Settings::getInstance().getFriendCircleID(frnd->getPublicKey());
|
||||
return settings.getFriendCircleID(frnd->getPublicKey());
|
||||
}
|
||||
|
||||
QString FriendChatroom::getCircleName() const
|
||||
{
|
||||
const auto circleId = getCircleId();
|
||||
return Settings::getInstance().getCircleName(circleId);
|
||||
return settings.getCircleName(circleId);
|
||||
}
|
||||
|
||||
void FriendChatroom::inviteToNewGroup()
|
||||
|
@ -93,13 +94,13 @@ void FriendChatroom::inviteToNewGroup()
|
|||
QString FriendChatroom::getAutoAcceptDir() const
|
||||
{
|
||||
const auto pk = frnd->getPublicKey();
|
||||
return Settings::getInstance().getAutoAcceptDir(pk);
|
||||
return settings.getAutoAcceptDir(pk);
|
||||
}
|
||||
|
||||
void FriendChatroom::setAutoAcceptDir(const QString& dir)
|
||||
{
|
||||
const auto pk = frnd->getPublicKey();
|
||||
Settings::getInstance().setAutoAcceptDir(pk, dir);
|
||||
settings.setAutoAcceptDir(pk, dir);
|
||||
}
|
||||
|
||||
void FriendChatroom::disableAutoAccept()
|
||||
|
@ -138,13 +139,12 @@ QVector<CircleToDisplay> FriendChatroom::getOtherCircles() const
|
|||
{
|
||||
QVector<CircleToDisplay> circles;
|
||||
const auto currentCircleId = getCircleId();
|
||||
const auto& s = Settings::getInstance();
|
||||
for (int i = 0; i < s.getCircleCount(); ++i) {
|
||||
for (int i = 0; i < settings.getCircleCount(); ++i) {
|
||||
if (i == currentCircleId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto name = getShortName(s.getCircleName(i));
|
||||
const auto name = getShortName(settings.getCircleName(i));
|
||||
const CircleToDisplay circle = { name, i };
|
||||
circles.push_back(circle);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ class Core;
|
|||
class IDialogsManager;
|
||||
class Friend;
|
||||
class Group;
|
||||
class Settings;
|
||||
|
||||
struct GroupToDisplay
|
||||
{
|
||||
|
@ -46,7 +47,8 @@ class FriendChatroom : public QObject, public Chatroom
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_);
|
||||
FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_,
|
||||
Settings& settings_);
|
||||
|
||||
Contact* getContact() override;
|
||||
|
||||
|
@ -87,4 +89,5 @@ private:
|
|||
Friend* frnd{nullptr};
|
||||
IDialogsManager* dialogsManager{nullptr};
|
||||
Core& core;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -99,9 +99,10 @@ bool tryRemoveFile(const QString& filepath)
|
|||
* @param profile Pointer to Profile.
|
||||
* @note All pointers parameters shouldn't be null.
|
||||
*/
|
||||
ProfileInfo::ProfileInfo(Core* core_, Profile* profile_)
|
||||
ProfileInfo::ProfileInfo(Core* core_, Profile* profile_, Settings& settings_)
|
||||
: profile{profile_}
|
||||
, core{core_}
|
||||
, settings{settings_}
|
||||
{
|
||||
connect(core_, &Core::idSet, this, &ProfileInfo::idChanged);
|
||||
connect(core_, &Core::usernameSet, this, &ProfileInfo::usernameChanged);
|
||||
|
@ -193,7 +194,7 @@ IProfileInfo::RenameResult ProfileInfo::renameProfile(const QString& name)
|
|||
|
||||
QString newName = sanitize(name);
|
||||
|
||||
if (Profile::exists(newName)) {
|
||||
if (Profile::exists(newName, settings.getPaths())) {
|
||||
return RenameResult::ProfileAlreadyExists;
|
||||
}
|
||||
|
||||
|
@ -220,7 +221,7 @@ IProfileInfo::SaveResult ProfileInfo::exportProfile(const QString& path) const
|
|||
return SaveResult::NoWritePermission;
|
||||
}
|
||||
|
||||
if (!QFile::copy(Settings::getInstance().getPaths().getSettingsDirPath() + current, path)) {
|
||||
if (!QFile::copy(settings.getPaths().getSettingsDirPath() + current, path)) {
|
||||
return SaveResult::Error;
|
||||
}
|
||||
|
||||
|
@ -244,9 +245,9 @@ QStringList ProfileInfo::removeProfile()
|
|||
void ProfileInfo::logout()
|
||||
{
|
||||
// TODO(kriby): Refactor all of these invokeMethod calls with connect() properly when possible
|
||||
Settings::getInstance().saveGlobal();
|
||||
settings.saveGlobal();
|
||||
QMetaObject::invokeMethod(&Nexus::getInstance(), "showLogin",
|
||||
Q_ARG(QString, Settings::getInstance().getCurrentProfile()));
|
||||
Q_ARG(QString, settings.getCurrentProfile()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,12 +28,13 @@ class Core;
|
|||
class QFile;
|
||||
class QPoint;
|
||||
class Profile;
|
||||
class Settings;
|
||||
|
||||
class ProfileInfo : public QObject, public IProfileInfo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProfileInfo(Core* core_, Profile* profile_);
|
||||
ProfileInfo(Core* core_, Profile* profile_, Settings&);
|
||||
|
||||
bool setPassword(const QString& password) override;
|
||||
bool deletePassword() override;
|
||||
|
@ -66,4 +67,5 @@ private:
|
|||
IProfileInfo::SetAvatarResult scalePngToAvatar(QByteArray& avatar);
|
||||
Profile* const profile;
|
||||
Core* const core;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -63,9 +63,7 @@ Nexus::Nexus(QObject* parent)
|
|||
: QObject(parent)
|
||||
, profile{nullptr}
|
||||
, widget{nullptr}
|
||||
, cameraSource(new CameraSource())
|
||||
{
|
||||
assert(cameraSource);
|
||||
}
|
||||
|
||||
Nexus::~Nexus()
|
||||
|
@ -163,7 +161,7 @@ int Nexus::showLogin(const QString& profileName)
|
|||
delete profile;
|
||||
profile = nullptr;
|
||||
|
||||
LoginScreen loginScreen{profileName};
|
||||
LoginScreen loginScreen{*settings, profileName};
|
||||
connectLoginScreen(loginScreen);
|
||||
|
||||
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
||||
|
@ -198,6 +196,7 @@ void Nexus::bootstrapWithProfile(Profile* p)
|
|||
|
||||
void Nexus::setSettings(Settings* settings_)
|
||||
{
|
||||
cameraSource = std::unique_ptr<CameraSource>(new CameraSource{*settings_});
|
||||
if (settings) {
|
||||
QObject::disconnect(this, &Nexus::saveGlobal, settings, &Settings::saveGlobal);
|
||||
}
|
||||
|
@ -231,7 +230,7 @@ void Nexus::showMainGUI()
|
|||
assert(profile);
|
||||
|
||||
// Create GUI
|
||||
widget = new Widget(*profile, *audioControl, *cameraSource);
|
||||
widget = new Widget(*profile, *audioControl, *cameraSource, *settings);
|
||||
|
||||
// Start GUI
|
||||
widget->init();
|
||||
|
|
|
@ -707,8 +707,9 @@ FileDbInsertionData::FileDbInsertionData()
|
|||
* @brief Prepares the database to work with the history.
|
||||
* @param db This database will be prepared for use with the history.
|
||||
*/
|
||||
History::History(std::shared_ptr<RawDatabase> db_)
|
||||
History::History(std::shared_ptr<RawDatabase> db_, Settings& settings_)
|
||||
: db(db_)
|
||||
, settings(settings_)
|
||||
{
|
||||
if (!isValid()) {
|
||||
qWarning() << "Database not open, init failed";
|
||||
|
@ -1385,7 +1386,7 @@ void History::markAsDelivered(RowId messageId)
|
|||
*/
|
||||
bool History::historyAccessBlocked()
|
||||
{
|
||||
if (!Settings::getInstance().getEnableLogging()) {
|
||||
if (!settings.getEnableLogging()) {
|
||||
assert(false);
|
||||
qCritical() << "Blocked history access while history is disabled";
|
||||
return true;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
class Profile;
|
||||
class HistoryKeeper;
|
||||
class Settings;
|
||||
|
||||
enum class HistMessageContentType
|
||||
{
|
||||
|
@ -185,7 +186,7 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
explicit History(std::shared_ptr<RawDatabase> db);
|
||||
History(std::shared_ptr<RawDatabase> db, Settings&);
|
||||
~History();
|
||||
|
||||
bool isValid();
|
||||
|
@ -245,4 +246,5 @@ private:
|
|||
|
||||
// This needs to be a shared pointer to avoid callback lifetime issues
|
||||
QHash<QString, FileInfo> fileInfos;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -132,7 +132,8 @@ fail:
|
|||
* @return Pointer to the tox encryption key.
|
||||
*/
|
||||
std::unique_ptr<ToxEncrypt> createToxData(const QString& name, const QString& password,
|
||||
const QString& filePath, CreateToxDataError& error)
|
||||
const QString& filePath, CreateToxDataError& error,
|
||||
Paths& paths)
|
||||
{
|
||||
std::unique_ptr<ToxEncrypt> newKey;
|
||||
if (!password.isEmpty()) {
|
||||
|
@ -153,7 +154,7 @@ std::unique_ptr<ToxEncrypt> createToxData(const QString& name, const QString& pa
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ProfileLocker::lock(name)) {
|
||||
if (!ProfileLocker::lock(name, paths)) {
|
||||
error = CreateToxDataError::LOCK_FAILED;
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -318,14 +319,14 @@ Profile* Profile::loadProfile(const QString& name, const QString& password, Sett
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ProfileLocker::lock(name)) {
|
||||
Paths& paths = settings.getPaths();
|
||||
if (!ProfileLocker::lock(name, paths)) {
|
||||
qWarning() << "Failed to lock profile " << name;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LoadToxDataError error;
|
||||
QByteArray toxsave = QByteArray();
|
||||
Paths& paths = settings.getPaths();
|
||||
QString path = paths.getSettingsDirPath() + name + ".tox";
|
||||
std::unique_ptr<ToxEncrypt> tmpKey = loadToxData(password, path, toxsave, error);
|
||||
if (logLoadToxDataError(error, path)) {
|
||||
|
@ -359,7 +360,7 @@ Profile* Profile::createProfile(const QString& name, const QString& password, Se
|
|||
CreateToxDataError error;
|
||||
Paths& paths = settings.getPaths();
|
||||
QString path = paths.getSettingsDirPath() + name + ".tox";
|
||||
std::unique_ptr<ToxEncrypt> tmpKey = createToxData(name, password, path, error);
|
||||
std::unique_ptr<ToxEncrypt> tmpKey = createToxData(name, password, path, error, paths);
|
||||
|
||||
if (logCreateToxDataError(error, name)) {
|
||||
return nullptr;
|
||||
|
@ -385,7 +386,7 @@ Profile::~Profile()
|
|||
onSaveToxSave();
|
||||
settings.savePersonal(this);
|
||||
settings.sync();
|
||||
ProfileLocker::assertLock();
|
||||
ProfileLocker::assertLock(paths);
|
||||
assert(ProfileLocker::getCurLockName() == name);
|
||||
ProfileLocker::unlock();
|
||||
}
|
||||
|
@ -395,9 +396,9 @@ Profile::~Profile()
|
|||
* @param extension Raw extension, e.g. "jpeg" not ".jpeg".
|
||||
* @return Vector of filenames.
|
||||
*/
|
||||
QStringList Profile::getFilesByExt(QString extension)
|
||||
QStringList Profile::getFilesByExt(QString extension, Settings& settings)
|
||||
{
|
||||
QDir dir(Settings::getInstance().getPaths().getSettingsDirPath());
|
||||
QDir dir(settings.getPaths().getSettingsDirPath());
|
||||
QStringList out;
|
||||
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
||||
dir.setNameFilters(QStringList("*." + extension));
|
||||
|
@ -414,13 +415,13 @@ QStringList Profile::getFilesByExt(QString extension)
|
|||
* @brief Scan for profile, automatically importing them if needed.
|
||||
* @warning NOT thread-safe.
|
||||
*/
|
||||
const QStringList Profile::getAllProfileNames()
|
||||
const QStringList Profile::getAllProfileNames(Settings& settings)
|
||||
{
|
||||
profiles.clear();
|
||||
QStringList toxfiles = getFilesByExt("tox"), inifiles = getFilesByExt("ini");
|
||||
QStringList toxfiles = getFilesByExt("tox", settings), inifiles = getFilesByExt("ini", settings);
|
||||
for (const QString& toxfile : toxfiles) {
|
||||
if (!inifiles.contains(toxfile)) {
|
||||
Settings::getInstance().createPersonal(toxfile);
|
||||
settings.createPersonal(toxfile);
|
||||
}
|
||||
|
||||
profiles.append(toxfile);
|
||||
|
@ -490,7 +491,7 @@ void Profile::onAvatarOfferReceived(uint32_t friendId, uint32_t fileId, const QB
|
|||
bool Profile::saveToxSave(QByteArray data)
|
||||
{
|
||||
assert(!isRemoved);
|
||||
ProfileLocker::assertLock();
|
||||
ProfileLocker::assertLock(paths);
|
||||
assert(ProfileLocker::getCurLockName() == name);
|
||||
|
||||
QString path = paths.getSettingsDirPath() + name + ".tox";
|
||||
|
@ -634,9 +635,10 @@ void Profile::loadDatabase(QString password)
|
|||
// At this point it's too early to load the personal settings (Nexus will do it), so we always
|
||||
// load
|
||||
// the history, and if it fails we can't change the setting now, but we keep a nullptr
|
||||
database = std::make_shared<RawDatabase>(getDbPath(name), password, salt);
|
||||
database = std::make_shared<RawDatabase>(getDbPath(name, settings.getPaths()),
|
||||
password, salt);
|
||||
if (database && database->isOpen()) {
|
||||
history.reset(new History(database));
|
||||
history.reset(new History(database, settings));
|
||||
} else {
|
||||
qWarning() << "Failed to open database for profile" << name;
|
||||
GUI::showError(QObject::tr("Error"),
|
||||
|
@ -804,9 +806,9 @@ void Profile::removeAvatar(const ToxPk& owner)
|
|||
}
|
||||
}
|
||||
|
||||
bool Profile::exists(QString name)
|
||||
bool Profile::exists(QString name, Paths& paths)
|
||||
{
|
||||
QString path = Settings::getInstance().getPaths().getSettingsDirPath() + name;
|
||||
QString path = paths.getSettingsDirPath() + name;
|
||||
return QFile::exists(path + ".tox");
|
||||
}
|
||||
|
||||
|
@ -825,10 +827,10 @@ bool Profile::isEncrypted() const
|
|||
* @param name Profile name.
|
||||
* @return True if profile is encrypted, false otherwise.
|
||||
*/
|
||||
bool Profile::isEncrypted(QString name)
|
||||
bool Profile::isEncrypted(QString name, Paths& paths)
|
||||
{
|
||||
uint8_t data[TOX_PASS_ENCRYPTION_EXTRA_LENGTH] = {0};
|
||||
QString path = Settings::getInstance().getPaths().getSettingsDirPath() + name + ".tox";
|
||||
QString path = paths.getSettingsDirPath() + name + ".tox";
|
||||
QFile saveFile(path);
|
||||
if (!saveFile.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Couldn't open tox save " << path;
|
||||
|
@ -879,7 +881,7 @@ QStringList Profile::remove()
|
|||
qWarning() << "Could not remove file " << profileConfig.fileName();
|
||||
}
|
||||
|
||||
QString dbPath = getDbPath(name);
|
||||
QString dbPath = getDbPath(name, settings.getPaths());
|
||||
if (database && database->isOpen() && !database->remove() && QFile::exists(dbPath)) {
|
||||
ret.push_back(dbPath);
|
||||
qWarning() << "Could not remove file " << dbPath;
|
||||
|
@ -901,7 +903,7 @@ bool Profile::rename(QString newName)
|
|||
QString path = paths.getSettingsDirPath() + name,
|
||||
newPath = paths.getSettingsDirPath() + newName;
|
||||
|
||||
if (!ProfileLocker::lock(newName)) {
|
||||
if (!ProfileLocker::lock(newName, paths)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -985,7 +987,7 @@ QString Profile::setPassword(const QString& newPassword)
|
|||
* @param profileName Profile name.
|
||||
* @return Path to database.
|
||||
*/
|
||||
QString Profile::getDbPath(const QString& profileName)
|
||||
QString Profile::getDbPath(const QString& profileName, Paths& paths)
|
||||
{
|
||||
return Settings::getInstance().getPaths().getSettingsDirPath() + profileName + ".db";
|
||||
return paths.getSettingsDirPath() + profileName + ".db";
|
||||
}
|
||||
|
|
|
@ -74,11 +74,11 @@ public:
|
|||
|
||||
bool rename(QString newName);
|
||||
|
||||
static const QStringList getAllProfileNames();
|
||||
static const QStringList getAllProfileNames(Settings&);
|
||||
|
||||
static bool exists(QString name);
|
||||
static bool isEncrypted(QString name);
|
||||
static QString getDbPath(const QString& profileName);
|
||||
static bool exists(QString name, Paths&);
|
||||
static bool isEncrypted(QString name, Paths&);
|
||||
static QString getDbPath(const QString& profileName, Paths&);
|
||||
|
||||
signals:
|
||||
void selfAvatarChanged(const QPixmap& pixmap);
|
||||
|
@ -106,7 +106,7 @@ private slots:
|
|||
|
||||
private:
|
||||
Profile(const QString& name_, std::unique_ptr<ToxEncrypt> passkey_, Paths& paths_, Settings &settings_);
|
||||
static QStringList getFilesByExt(QString extension);
|
||||
static QStringList getFilesByExt(QString extension, Settings& settings);
|
||||
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
|
||||
bool saveToxSave(QByteArray data);
|
||||
void initCore(const QByteArray& toxsave, Settings &s, bool isNewProfile, CameraSource&);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "profilelocker.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/persistence/paths.h"
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
|
@ -36,9 +37,9 @@ using namespace std;
|
|||
unique_ptr<QLockFile> ProfileLocker::lockfile;
|
||||
QString ProfileLocker::curLockName;
|
||||
|
||||
QString ProfileLocker::lockPathFromName(const QString& name)
|
||||
QString ProfileLocker::lockPathFromName(const QString& name, const Paths& paths)
|
||||
{
|
||||
return Settings::getInstance().getPaths().getSettingsDirPath() + '/' + name + ".lock";
|
||||
return paths.getSettingsDirPath() + '/' + name + ".lock";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,13 +50,13 @@ QString ProfileLocker::lockPathFromName(const QString& name)
|
|||
* @param profile Profile name to check.
|
||||
* @return True, if profile locked, false otherwise.
|
||||
*/
|
||||
bool ProfileLocker::isLockable(QString profile)
|
||||
bool ProfileLocker::isLockable(QString profile, Paths& paths)
|
||||
{
|
||||
// If we already have the lock, it's definitely lockable
|
||||
if (lockfile && curLockName == profile)
|
||||
return true;
|
||||
|
||||
QLockFile newLock(lockPathFromName(profile));
|
||||
QLockFile newLock(lockPathFromName(profile, paths));
|
||||
return newLock.tryLock();
|
||||
}
|
||||
|
||||
|
@ -64,12 +65,12 @@ bool ProfileLocker::isLockable(QString profile)
|
|||
* @param profile Profile to lock.
|
||||
* @return Returns true if we already own the lock.
|
||||
*/
|
||||
bool ProfileLocker::lock(QString profile)
|
||||
bool ProfileLocker::lock(QString profile, Paths& paths)
|
||||
{
|
||||
if (lockfile && curLockName == profile)
|
||||
return true;
|
||||
|
||||
QLockFile* newLock = new QLockFile(lockPathFromName(profile));
|
||||
QLockFile* newLock = new QLockFile(lockPathFromName(profile, paths));
|
||||
newLock->setStaleLockTime(0);
|
||||
if (!newLock->tryLock()) {
|
||||
delete newLock;
|
||||
|
@ -101,17 +102,17 @@ void ProfileLocker::unlock()
|
|||
* If we can't get a lock, exit qTox immediately.
|
||||
* If we never had a lock in the first place, exit immediately.
|
||||
*/
|
||||
void ProfileLocker::assertLock()
|
||||
void ProfileLocker::assertLock(Paths& paths)
|
||||
{
|
||||
if (!lockfile) {
|
||||
qCritical() << "assertLock: We don't seem to own any lock!";
|
||||
deathByBrokenLock();
|
||||
}
|
||||
|
||||
if (!QFile(lockPathFromName(curLockName)).exists()) {
|
||||
if (!QFile(lockPathFromName(curLockName, paths)).exists()) {
|
||||
QString tmp = curLockName;
|
||||
unlock();
|
||||
if (lock(tmp)) {
|
||||
if (lock(tmp, paths)) {
|
||||
qCritical() << "assertLock: Lock file was lost, but could be restored";
|
||||
} else {
|
||||
qCritical() << "assertLock: Lock file was lost, and could *NOT* be restored";
|
||||
|
|
|
@ -23,21 +23,23 @@
|
|||
#include <QLockFile>
|
||||
#include <memory>
|
||||
|
||||
class Paths;
|
||||
|
||||
class ProfileLocker
|
||||
{
|
||||
private:
|
||||
ProfileLocker() = delete;
|
||||
|
||||
public:
|
||||
static bool isLockable(QString profile);
|
||||
static bool lock(QString profile);
|
||||
static bool isLockable(QString profile, Paths&);
|
||||
static bool lock(QString profile, Paths&);
|
||||
static void unlock();
|
||||
static bool hasLock();
|
||||
static QString getCurLockName();
|
||||
static void assertLock();
|
||||
static void assertLock(Paths&);
|
||||
|
||||
private:
|
||||
static QString lockPathFromName(const QString& name);
|
||||
static QString lockPathFromName(const QString& name, const Paths&);
|
||||
static void deathByBrokenLock();
|
||||
|
||||
private:
|
||||
|
|
|
@ -61,7 +61,6 @@
|
|||
*/
|
||||
|
||||
const QString Settings::globalSettingsFile = "qtox.ini";
|
||||
Settings* Settings::settings{nullptr};
|
||||
CompatibleRecursiveMutex Settings::bigLock;
|
||||
QThread* Settings::settingsThread{nullptr};
|
||||
static constexpr int GLOBAL_SETTINGS_VERSION = 1;
|
||||
|
@ -87,23 +86,6 @@ Settings::~Settings()
|
|||
delete settingsThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the singleton instance.
|
||||
*/
|
||||
Settings& Settings::getInstance()
|
||||
{
|
||||
if (!settings)
|
||||
settings = new Settings();
|
||||
|
||||
return *settings;
|
||||
}
|
||||
|
||||
void Settings::destroyInstance()
|
||||
{
|
||||
delete settings;
|
||||
settings = nullptr;
|
||||
}
|
||||
|
||||
void Settings::loadGlobal()
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
@ -624,7 +606,7 @@ void Settings::resetToDefault()
|
|||
void Settings::saveGlobal()
|
||||
{
|
||||
if (QThread::currentThread() != settingsThread)
|
||||
return (void)QMetaObject::invokeMethod(&getInstance(), "saveGlobal");
|
||||
return (void)QMetaObject::invokeMethod(this, "saveGlobal");
|
||||
|
||||
QMutexLocker locker{&bigLock};
|
||||
if (!loaded)
|
||||
|
@ -778,7 +760,7 @@ void Settings::savePersonal(Profile* profile)
|
|||
return;
|
||||
}
|
||||
if (QThread::currentThread() != settingsThread)
|
||||
return (void)QMetaObject::invokeMethod(&getInstance(), "savePersonal",
|
||||
return (void)QMetaObject::invokeMethod(this, "savePersonal",
|
||||
Q_ARG(Profile*, profile));
|
||||
savePersonal(profile->getName(), profile->getPasskey());
|
||||
}
|
||||
|
@ -942,7 +924,7 @@ bool Settings::getAutorun() const
|
|||
QMutexLocker locker{&bigLock};
|
||||
|
||||
#ifdef QTOX_PLATFORM_EXT
|
||||
return Platform::getAutorun();
|
||||
return Platform::getAutorun(*this);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@ -951,10 +933,10 @@ bool Settings::getAutorun() const
|
|||
void Settings::setAutorun(bool newValue)
|
||||
{
|
||||
#ifdef QTOX_PLATFORM_EXT
|
||||
bool autorun = Platform::getAutorun();
|
||||
bool autorun = Platform::getAutorun(*this);
|
||||
|
||||
if (newValue != autorun) {
|
||||
Platform::setAutorun(newValue);
|
||||
Platform::setAutorun(*this, newValue);
|
||||
emit autorunChanged(autorun);
|
||||
}
|
||||
#else
|
||||
|
@ -2261,7 +2243,7 @@ void Settings::createSettingsDir()
|
|||
void Settings::sync()
|
||||
{
|
||||
if (QThread::currentThread() != settingsThread) {
|
||||
QMetaObject::invokeMethod(&getInstance(), "sync", Qt::BlockingQueuedConnection);
|
||||
QMetaObject::invokeMethod(this, "sync", Qt::BlockingQueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,8 +145,10 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
static Settings& getInstance();
|
||||
static void destroyInstance();
|
||||
Settings();
|
||||
~Settings();
|
||||
Settings(Settings& settings) = delete;
|
||||
Settings& operator=(const Settings&) = delete;
|
||||
|
||||
Paths& getPaths();
|
||||
void createSettingsDir();
|
||||
|
@ -568,11 +570,6 @@ public:
|
|||
|
||||
private:
|
||||
struct friendProp;
|
||||
|
||||
Settings();
|
||||
~Settings();
|
||||
Settings(Settings& settings) = delete;
|
||||
Settings& operator=(const Settings&) = delete;
|
||||
void savePersonal(QString profileName, const ToxEncrypt* passkey);
|
||||
friendProp& getOrInsertFriendPropRef(const ToxPk& id);
|
||||
static ICoreSettings::ProxyType fixInvalidProxyType(ICoreSettings::ProxyType proxyType);
|
||||
|
@ -712,7 +709,6 @@ private:
|
|||
int themeColor;
|
||||
|
||||
static CompatibleRecursiveMutex bigLock;
|
||||
static Settings* settings;
|
||||
static const QString globalSettingsFile;
|
||||
static QThread* settingsThread;
|
||||
Paths paths;
|
||||
|
|
|
@ -105,12 +105,13 @@ bool isAscii(const QString& string)
|
|||
|
||||
} // namespace
|
||||
|
||||
SmileyPack::SmileyPack()
|
||||
SmileyPack::SmileyPack(Settings& settings_)
|
||||
: cleanupTimer{new QTimer(this)}
|
||||
, settings{settings_}
|
||||
{
|
||||
loadingMutex.lock();
|
||||
QtConcurrent::run(this, &SmileyPack::load, Settings::getInstance().getSmileyPack());
|
||||
connect(&Settings::getInstance(), &Settings::smileyPackChanged, this,
|
||||
QtConcurrent::run(this, &SmileyPack::load, settings.getSmileyPack());
|
||||
connect(&settings, &Settings::smileyPackChanged, this,
|
||||
&SmileyPack::onSmileyPackChanged);
|
||||
connect(cleanupTimer, &QTimer::timeout, this, &SmileyPack::cleanupIconsCache);
|
||||
cleanupTimer->start(CLEANUP_TIMEOUT);
|
||||
|
@ -348,5 +349,5 @@ std::shared_ptr<QIcon> SmileyPack::getAsIcon(const QString& emoticon) const
|
|||
void SmileyPack::onSmileyPackChanged()
|
||||
{
|
||||
loadingMutex.lock();
|
||||
QtConcurrent::run(this, &SmileyPack::load, Settings::getInstance().getSmileyPack());
|
||||
QtConcurrent::run(this, &SmileyPack::load, settings.getSmileyPack());
|
||||
}
|
||||
|
|
|
@ -27,13 +27,14 @@
|
|||
#include <memory>
|
||||
|
||||
class QTimer;
|
||||
class Settings;
|
||||
|
||||
class SmileyPack : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SmileyPack();
|
||||
explicit SmileyPack(Settings&);
|
||||
SmileyPack(SmileyPack&) = delete;
|
||||
SmileyPack& operator=(const SmileyPack&) = delete;
|
||||
~SmileyPack() override;
|
||||
|
@ -61,4 +62,5 @@ private:
|
|||
QTimer* cleanupTimer;
|
||||
QRegularExpression smilify;
|
||||
mutable QMutex loadingMutex;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -18,17 +18,24 @@
|
|||
*/
|
||||
|
||||
#include "toxsave.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/widget/gui.h"
|
||||
#include "src/widget/tool/profileimporter.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
bool toxSaveEventHandler(const QByteArray& eventData)
|
||||
ToxSave::ToxSave(Settings& settings_)
|
||||
: settings{settings_}
|
||||
{}
|
||||
|
||||
bool ToxSave::toxSaveEventHandler(const QByteArray& eventData, void* userData)
|
||||
{
|
||||
auto toxSave = static_cast<ToxSave*>(userData);
|
||||
|
||||
if (!eventData.endsWith(".tox")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
handleToxSave(eventData);
|
||||
toxSave->handleToxSave(eventData);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,8 +45,8 @@ bool toxSaveEventHandler(const QByteArray& eventData)
|
|||
* @param path Path to .tox file.
|
||||
* @return True if import success, false, otherwise.
|
||||
*/
|
||||
bool handleToxSave(const QString& path)
|
||||
bool ToxSave::handleToxSave(const QString& path)
|
||||
{
|
||||
ProfileImporter importer(GUI::getMainWidget());
|
||||
ProfileImporter importer(settings, GUI::getMainWidget());
|
||||
return importer.importProfile(path);
|
||||
}
|
||||
|
|
|
@ -21,8 +21,15 @@
|
|||
|
||||
class QString;
|
||||
class QByteArray;
|
||||
class Settings;
|
||||
|
||||
bool handleToxSave(const QString& path);
|
||||
class ToxSave
|
||||
{
|
||||
public:
|
||||
explicit ToxSave(Settings&);
|
||||
bool handleToxSave(const QString& path);
|
||||
static bool toxSaveEventHandler(const QByteArray& eventData, void* userData);
|
||||
|
||||
// Internals
|
||||
bool toxSaveEventHandler(const QByteArray& eventData);
|
||||
private:
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
|
||||
#ifdef QTOX_PLATFORM_EXT
|
||||
|
||||
|
||||
class Settings;
|
||||
namespace Platform {
|
||||
bool setAutorun(bool on);
|
||||
bool getAutorun();
|
||||
bool setAutorun(const Settings&, bool on);
|
||||
bool getAutorun(const Settings&);
|
||||
}
|
||||
|
||||
#endif // QTOX_PLATFORM_EXT
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace {
|
|||
int state;
|
||||
} // namespace
|
||||
|
||||
bool Platform::setAutorun(bool on)
|
||||
bool Platform::setAutorun(const Settings&, bool on)
|
||||
{
|
||||
QString qtoxPlist =
|
||||
QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
|
||||
|
@ -45,7 +45,7 @@ bool Platform::setAutorun(bool on)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Platform::getAutorun()
|
||||
bool Platform::getAutorun(const Settings&)
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -45,19 +45,19 @@ inline tstring toTString(QString s)
|
|||
} // namespace
|
||||
|
||||
namespace Platform {
|
||||
inline tstring currentCommandLine()
|
||||
inline tstring currentCommandLine(const Settings& settings)
|
||||
{
|
||||
return toTString("\"" + QApplication::applicationFilePath().replace('/', '\\') + "\" -p \""
|
||||
+ Settings::getInstance().getCurrentProfile() + "\"");
|
||||
+ settings.getCurrentProfile() + "\"");
|
||||
}
|
||||
|
||||
inline tstring currentRegistryKeyName()
|
||||
inline tstring currentRegistryKeyName(const Settings& settings)
|
||||
{
|
||||
return toTString("qTox - " + Settings::getInstance().getCurrentProfile());
|
||||
return toTString("qTox - " + settings.getCurrentProfile());
|
||||
}
|
||||
}
|
||||
|
||||
bool Platform::setAutorun(bool on)
|
||||
bool Platform::setAutorun(const Settings& settings, bool on)
|
||||
{
|
||||
HKEY key = nullptr;
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
|
||||
|
@ -66,10 +66,10 @@ bool Platform::setAutorun(bool on)
|
|||
return false;
|
||||
|
||||
bool result = false;
|
||||
tstring keyName = currentRegistryKeyName();
|
||||
tstring keyName = currentRegistryKeyName(settings);
|
||||
|
||||
if (on) {
|
||||
tstring path = currentCommandLine();
|
||||
tstring path = currentCommandLine(settings);
|
||||
result = RegSetValueEx(key, keyName.c_str(), 0, REG_SZ, const_cast<PBYTE>(reinterpret_cast<const unsigned char*>(path.c_str())),
|
||||
path.length() * sizeof(TCHAR))
|
||||
== ERROR_SUCCESS;
|
||||
|
@ -80,7 +80,7 @@ bool Platform::setAutorun(bool on)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Platform::getAutorun()
|
||||
bool Platform::getAutorun(const Settings& settings)
|
||||
{
|
||||
HKEY key = nullptr;
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
|
||||
|
@ -88,7 +88,7 @@ bool Platform::getAutorun()
|
|||
!= ERROR_SUCCESS)
|
||||
return false;
|
||||
|
||||
tstring keyName = currentRegistryKeyName();
|
||||
tstring keyName = currentRegistryKeyName(settings);
|
||||
|
||||
TCHAR path[MAX_PATH] = {0};
|
||||
DWORD length = sizeof(path);
|
||||
|
|
|
@ -33,9 +33,9 @@ QString getAutostartDirPath()
|
|||
return config + "/autostart";
|
||||
}
|
||||
|
||||
QString getAutostartFilePath(QString dir)
|
||||
QString getAutostartFilePath(const Settings& settings, QString dir)
|
||||
{
|
||||
return dir + "/qTox - " + Settings::getInstance().getCurrentProfile() + ".desktop";
|
||||
return dir + "/qTox - " + settings.getCurrentProfile() + ".desktop";
|
||||
}
|
||||
|
||||
QString currentBinPath()
|
||||
|
@ -50,17 +50,17 @@ QString currentBinPath()
|
|||
}
|
||||
}
|
||||
|
||||
inline QString profileRunCommand()
|
||||
inline QString profileRunCommand(const Settings& settings)
|
||||
{
|
||||
return "\"" + currentBinPath() + "\" -p \""
|
||||
+ Settings::getInstance().getCurrentProfile() + "\"";
|
||||
+ settings.getCurrentProfile() + "\"";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool Platform::setAutorun(bool on)
|
||||
bool Platform::setAutorun(const Settings& settings, bool on)
|
||||
{
|
||||
QString dirPath = getAutostartDirPath();
|
||||
QFile desktop(getAutostartFilePath(dirPath));
|
||||
QFile desktop(getAutostartFilePath(settings, dirPath));
|
||||
if (on) {
|
||||
if (!QDir().mkpath(dirPath) || !desktop.open(QFile::WriteOnly | QFile::Truncate))
|
||||
return false;
|
||||
|
@ -68,7 +68,7 @@ bool Platform::setAutorun(bool on)
|
|||
desktop.write("Type=Application\n");
|
||||
desktop.write("Name=qTox\n");
|
||||
desktop.write("Exec=");
|
||||
desktop.write(profileRunCommand().toUtf8());
|
||||
desktop.write(profileRunCommand(settings).toUtf8());
|
||||
desktop.write("\n");
|
||||
desktop.close();
|
||||
return true;
|
||||
|
@ -76,7 +76,7 @@ bool Platform::setAutorun(bool on)
|
|||
return desktop.remove();
|
||||
}
|
||||
|
||||
bool Platform::getAutorun()
|
||||
bool Platform::getAutorun(const Settings& settings)
|
||||
{
|
||||
return QFile(getAutostartFilePath(getAutostartDirPath())).exists();
|
||||
return QFile(getAutostartFilePath(settings, getAutostartDirPath())).exists();
|
||||
}
|
||||
|
|
|
@ -27,9 +27,10 @@
|
|||
#include <QDebug>
|
||||
#include <QThread>
|
||||
|
||||
DesktopNotify::DesktopNotify()
|
||||
DesktopNotify::DesktopNotify(Settings& settings_)
|
||||
: notifyCore{Snore::SnoreCore::instance()}
|
||||
, snoreIcon{":/img/icons/qtox.svg"}
|
||||
, settings{settings_}
|
||||
{
|
||||
|
||||
notifyCore.loadPlugins(Snore::SnorePlugin::Backend);
|
||||
|
@ -44,8 +45,7 @@ DesktopNotify::DesktopNotify()
|
|||
|
||||
void DesktopNotify::notifyMessage(const NotificationData& notificationData)
|
||||
{
|
||||
const Settings& s = Settings::getInstance();
|
||||
if(!(s.getNotify() && s.getDesktopNotify())) {
|
||||
if(!(settings.getNotify() && settings.getDesktopNotify())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,11 +28,13 @@
|
|||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
class Settings;
|
||||
|
||||
class DesktopNotify : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DesktopNotify();
|
||||
explicit DesktopNotify(Settings&);
|
||||
|
||||
public slots:
|
||||
void notifyMessage(const NotificationData& notificationData);
|
||||
|
@ -49,4 +51,5 @@ private:
|
|||
Snore::Icon snoreIcon;
|
||||
Snore::Notification lastNotification;
|
||||
uint latestId;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -79,14 +79,16 @@ AvFindInputFormatRet iformat{nullptr};
|
|||
QHash<QString, CameraDevice*> CameraDevice::openDevices;
|
||||
QMutex CameraDevice::openDeviceLock, CameraDevice::iformatLock;
|
||||
|
||||
CameraDevice::CameraDevice(const QString& devName_, AVFormatContext* context_)
|
||||
CameraDevice::CameraDevice(const QString& devName_, AVFormatContext* context_,
|
||||
Settings& settings_)
|
||||
: devName{devName_}
|
||||
, context{context_}
|
||||
, refcount{1}
|
||||
, settings{settings_}
|
||||
{
|
||||
}
|
||||
|
||||
CameraDevice* CameraDevice::open(QString devName, AVDictionary** options)
|
||||
CameraDevice* CameraDevice::open(Settings& settings, QString devName, AVDictionary** options)
|
||||
{
|
||||
openDeviceLock.lock();
|
||||
AVFormatContext* fctx = nullptr;
|
||||
|
@ -131,7 +133,7 @@ CameraDevice* CameraDevice::open(QString devName, AVDictionary** options)
|
|||
fctx->max_analyze_duration = aduration;
|
||||
#endif
|
||||
|
||||
dev = new CameraDevice{devName, fctx};
|
||||
dev = new CameraDevice{devName, fctx, settings};
|
||||
openDevices[devName] = dev;
|
||||
|
||||
out:
|
||||
|
@ -151,7 +153,7 @@ out:
|
|||
* @param mode Mode of device to open.
|
||||
* @return CameraDevice if the device could be opened, nullptr otherwise.
|
||||
*/
|
||||
CameraDevice* CameraDevice::open(QString devName, VideoMode mode)
|
||||
CameraDevice* CameraDevice::open(Settings& settings, QString devName, VideoMode mode)
|
||||
{
|
||||
if (!getDefaultInputFormat())
|
||||
return nullptr;
|
||||
|
@ -237,7 +239,7 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode)
|
|||
std::ignore = mode;
|
||||
}
|
||||
|
||||
CameraDevice* dev = open(devName, &options);
|
||||
CameraDevice* dev = open(settings, devName, &options);
|
||||
if (options) {
|
||||
av_dict_free(&options);
|
||||
}
|
||||
|
@ -395,9 +397,9 @@ QVector<QPair<QString, QString>> CameraDevice::getDeviceList()
|
|||
* @return The short name of the default device
|
||||
* This is either the device in the settings or the system default.
|
||||
*/
|
||||
QString CameraDevice::getDefaultDeviceName()
|
||||
QString CameraDevice::getDefaultDeviceName(Settings& settings)
|
||||
{
|
||||
QString defaultdev = Settings::getInstance().getVideoDev();
|
||||
QString defaultdev = settings.getVideoDev();
|
||||
|
||||
if (!getDefaultInputFormat())
|
||||
return defaultdev;
|
||||
|
|
|
@ -31,11 +31,12 @@ struct AVFormatContext;
|
|||
struct AVInputFormat;
|
||||
struct AVDeviceInfoList;
|
||||
struct AVDictionary;
|
||||
class Settings;
|
||||
|
||||
class CameraDevice
|
||||
{
|
||||
public:
|
||||
static CameraDevice* open(QString devName, VideoMode mode = VideoMode());
|
||||
static CameraDevice* open(Settings&, QString devName, VideoMode mode = VideoMode());
|
||||
void open();
|
||||
bool close();
|
||||
|
||||
|
@ -45,13 +46,13 @@ public:
|
|||
static QString getPixelFormatString(uint32_t pixel_format);
|
||||
static bool betterPixelFormat(uint32_t a, uint32_t b);
|
||||
|
||||
static QString getDefaultDeviceName();
|
||||
static QString getDefaultDeviceName(Settings& settings);
|
||||
|
||||
static bool isScreen(const QString& devName);
|
||||
|
||||
private:
|
||||
CameraDevice(const QString& devName_, AVFormatContext* context_);
|
||||
static CameraDevice* open(QString devName, AVDictionary** options);
|
||||
CameraDevice(const QString& devName_, AVFormatContext* context_, Settings&);
|
||||
static CameraDevice* open(Settings&, QString devName, AVDictionary** options);
|
||||
static bool getDefaultInputFormat();
|
||||
static QVector<QPair<QString, QString>> getRawDeviceListGeneric();
|
||||
static QVector<VideoMode> getScreenModes();
|
||||
|
@ -64,4 +65,5 @@ private:
|
|||
std::atomic_int refcount;
|
||||
static QHash<QString, CameraDevice*> openDevices;
|
||||
static QMutex openDeviceLock, iformatLock;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -90,7 +90,7 @@ extern "C" {
|
|||
* @brief Remember how many times we subscribed for RAII
|
||||
*/
|
||||
|
||||
CameraSource::CameraSource()
|
||||
CameraSource::CameraSource(Settings& settings_)
|
||||
: deviceThread{new QThread}
|
||||
, deviceName{"none"}
|
||||
, device{nullptr}
|
||||
|
@ -103,6 +103,7 @@ CameraSource::CameraSource()
|
|||
, videoStreamIndex{-1}
|
||||
, isNone_{true}
|
||||
, subscriptions{0}
|
||||
, settings{settings_}
|
||||
{
|
||||
qRegisterMetaType<VideoMode>("VideoMode");
|
||||
deviceThread->setObjectName("Device thread");
|
||||
|
@ -126,12 +127,12 @@ CameraSource::CameraSource()
|
|||
*/
|
||||
void CameraSource::setupDefault()
|
||||
{
|
||||
QString deviceName_ = CameraDevice::getDefaultDeviceName();
|
||||
QString deviceName_ = CameraDevice::getDefaultDeviceName(settings);
|
||||
bool isScreen = CameraDevice::isScreen(deviceName_);
|
||||
VideoMode mode_ = VideoMode(Settings::getInstance().getScreenRegion());
|
||||
VideoMode mode_ = VideoMode(settings.getScreenRegion());
|
||||
if (!isScreen) {
|
||||
mode_ = VideoMode(Settings::getInstance().getCamVideoRes());
|
||||
mode_.FPS = Settings::getInstance().getCamVideoFPS();
|
||||
mode_ = VideoMode(settings.getCamVideoRes());
|
||||
mode_.FPS = settings.getCamVideoFPS();
|
||||
}
|
||||
|
||||
setupDevice(deviceName_, mode_);
|
||||
|
@ -260,7 +261,7 @@ void CameraSource::openDevice()
|
|||
}
|
||||
|
||||
// We need to create a new CameraDevice
|
||||
device = CameraDevice::open(deviceName, mode);
|
||||
device = CameraDevice::open(settings, deviceName, mode);
|
||||
|
||||
if (!device) {
|
||||
qWarning() << "Failed to open device!";
|
||||
|
|
|
@ -30,13 +30,14 @@
|
|||
|
||||
class CameraDevice;
|
||||
struct AVCodecContext;
|
||||
class Settings;
|
||||
|
||||
class CameraSource : public VideoSource
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CameraSource();
|
||||
explicit CameraSource(Settings&);
|
||||
~CameraSource();
|
||||
void setupDefault();
|
||||
bool isNone() const;
|
||||
|
@ -76,4 +77,5 @@ private:
|
|||
|
||||
std::atomic_bool isNone_;
|
||||
std::atomic_int subscriptions;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -47,12 +47,14 @@ const int BTN_PANEL_WIDTH = 250;
|
|||
const auto BTN_STYLE_SHEET_PATH = QStringLiteral("chatForm/fullScreenButtons.css");
|
||||
}
|
||||
|
||||
NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_, QWidget* parent)
|
||||
NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_,
|
||||
Settings& settings_, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, selfFrame{nullptr}
|
||||
, friendPk{friendPk_}
|
||||
, e(false)
|
||||
, cameraSource{cameraSource_}
|
||||
, settings{settings_}
|
||||
{
|
||||
verLayout = new QVBoxLayout(this);
|
||||
setWindowTitle(tr("Tox video"));
|
||||
|
@ -77,7 +79,7 @@ NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_, QWidget* pa
|
|||
|
||||
setStyleSheet("NetCamView { background-color: #c1c1c1; }");
|
||||
buttonPanel = new QFrame(this);
|
||||
buttonPanel->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH));
|
||||
buttonPanel->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
|
||||
buttonPanel->setGeometry(0, 0, BTN_PANEL_WIDTH, BTN_PANEL_HEIGHT);
|
||||
|
||||
QHBoxLayout* buttonPanelLayout = new QHBoxLayout(buttonPanel);
|
||||
|
@ -155,7 +157,7 @@ NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_, QWidget* pa
|
|||
videoSurface->setAvatar(pixmap);
|
||||
});
|
||||
|
||||
QRect videoSize = Settings::getInstance().getCamVideoRes();
|
||||
QRect videoSize = settings.getCamVideoRes();
|
||||
qDebug() << "SIZER" << videoSize;
|
||||
}
|
||||
|
||||
|
@ -239,7 +241,7 @@ void NetCamView::setShowMessages(bool show, bool notify)
|
|||
toggleMessagesButton->setText(tr("Show messages"));
|
||||
|
||||
if (notify) {
|
||||
toggleMessagesButton->setIcon(QIcon(Style::getImagePath("chatArea/info.svg")));
|
||||
toggleMessagesButton->setIcon(QIcon(Style::getImagePath("chatArea/info.svg", settings)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,7 +303,7 @@ QPushButton* NetCamView::createButton(const QString& name, const QString& state)
|
|||
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
btn->setObjectName(name);
|
||||
btn->setProperty("state", QVariant(state));
|
||||
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH));
|
||||
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
|
||||
|
||||
return btn;
|
||||
}
|
||||
|
@ -324,7 +326,7 @@ void NetCamView::toggleButtonState(QPushButton* btn)
|
|||
btn->setProperty("state", BTN_STATE_RED);
|
||||
}
|
||||
|
||||
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH));
|
||||
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
|
||||
}
|
||||
|
||||
void NetCamView::updateButtonState(QPushButton* btn, bool active)
|
||||
|
@ -335,7 +337,7 @@ void NetCamView::updateButtonState(QPushButton* btn, bool active)
|
|||
btn->setProperty("state", BTN_STATE_RED);
|
||||
}
|
||||
|
||||
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH));
|
||||
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
|
||||
}
|
||||
|
||||
void NetCamView::keyPressEvent(QKeyEvent *event)
|
||||
|
|
|
@ -35,13 +35,14 @@ class QKeyEvent;
|
|||
class QCloseEvent;
|
||||
class QShowEvent;
|
||||
class CameraSource;
|
||||
class Settings;
|
||||
|
||||
class NetCamView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NetCamView(ToxPk friendPk_, CameraSource&, QWidget* parent = nullptr);
|
||||
NetCamView(ToxPk friendPk_, CameraSource&, Settings&, QWidget* parent = nullptr);
|
||||
~NetCamView();
|
||||
|
||||
virtual void show(VideoSource* source, const QString& title);
|
||||
|
@ -97,4 +98,5 @@ private:
|
|||
QPushButton* endVideoButton = nullptr;
|
||||
QPushButton* exitFullScreenButton = nullptr;
|
||||
CameraSource& cameraSource;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -36,10 +36,11 @@ QString getAutoAcceptDir(const QString& dir)
|
|||
|
||||
} // namespace
|
||||
|
||||
AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget* parent)
|
||||
AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> about_, Settings& settings_, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::AboutFriendForm)
|
||||
, about{std::move(_about)}
|
||||
, about{std::move(about_)}
|
||||
, settings{settings_}
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->label_4->hide();
|
||||
|
@ -97,7 +98,7 @@ void AboutFriendForm::onAutoAcceptDirClicked()
|
|||
|
||||
void AboutFriendForm::reloadTheme()
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet("window/general.css"));
|
||||
setStyleSheet(Style::getStylesheet("window/general.css", settings));
|
||||
}
|
||||
|
||||
void AboutFriendForm::onAutoAcceptDirChanged(const QString& path)
|
||||
|
|
|
@ -30,17 +30,20 @@ namespace Ui {
|
|||
class AboutFriendForm;
|
||||
}
|
||||
|
||||
class Settings;
|
||||
|
||||
class AboutFriendForm : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AboutFriendForm(std::unique_ptr<IAboutFriend> about, QWidget* parent = nullptr);
|
||||
AboutFriendForm(std::unique_ptr<IAboutFriend> about, Settings&, QWidget* parent = nullptr);
|
||||
~AboutFriendForm();
|
||||
|
||||
private:
|
||||
Ui::AboutFriendForm* ui;
|
||||
const std::unique_ptr<IAboutFriend> about;
|
||||
Settings& settings;
|
||||
|
||||
signals:
|
||||
void histroyRemoved();
|
||||
|
|
|
@ -38,8 +38,9 @@ void CategoryWidget::emitChatroomWidget(QLayout* layout, int index)
|
|||
}
|
||||
}
|
||||
|
||||
CategoryWidget::CategoryWidget(bool compact_, QWidget* parent)
|
||||
CategoryWidget::CategoryWidget(bool compact_, Settings& settings_, QWidget* parent)
|
||||
: GenericChatItemWidget(compact_, parent)
|
||||
, settings{settings_}
|
||||
{
|
||||
container = new QWidget(this);
|
||||
container->setObjectName("circleWidgetContainer");
|
||||
|
@ -49,7 +50,7 @@ CategoryWidget::CategoryWidget(bool compact_, QWidget* parent)
|
|||
statusLabel->setObjectName("status");
|
||||
statusLabel->setTextFormat(Qt::PlainText);
|
||||
|
||||
statusPic.setPixmap(QPixmap(Style::getImagePath("chatArea/scrollBarRightArrow.svg")));
|
||||
statusPic.setPixmap(QPixmap(Style::getImagePath("chatArea/scrollBarRightArrow.svg", settings)));
|
||||
|
||||
fullLayout = new QVBoxLayout(this);
|
||||
fullLayout->setSpacing(0);
|
||||
|
@ -96,9 +97,9 @@ void CategoryWidget::setExpanded(bool isExpanded, bool save)
|
|||
|
||||
QString pixmapPath;
|
||||
if (isExpanded)
|
||||
pixmapPath = Style::getImagePath("chatArea/scrollBarDownArrow.svg");
|
||||
pixmapPath = Style::getImagePath("chatArea/scrollBarDownArrow.svg", settings);
|
||||
else
|
||||
pixmapPath = Style::getImagePath("chatArea/scrollBarRightArrow.svg");
|
||||
pixmapPath = Style::getImagePath("chatArea/scrollBarRightArrow.svg", settings);
|
||||
statusPic.setPixmap(QPixmap(pixmapPath));
|
||||
|
||||
if (save)
|
||||
|
|
|
@ -28,12 +28,13 @@ class FriendListWidget;
|
|||
class FriendWidget;
|
||||
class QVBoxLayout;
|
||||
class QHBoxLayout;
|
||||
class Settings;
|
||||
|
||||
class CategoryWidget : public GenericChatItemWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CategoryWidget(bool compact_, QWidget* parent = nullptr);
|
||||
explicit CategoryWidget(bool compact_, Settings&, QWidget* parent = nullptr);
|
||||
|
||||
bool isExpanded() const;
|
||||
void setExpanded(bool isExpanded, bool save = true);
|
||||
|
@ -83,4 +84,5 @@ private:
|
|||
QWidget* container;
|
||||
QFrame* lineFrame;
|
||||
bool expanded = false;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -81,12 +81,12 @@ const QString MIC_TOOL_TIP[] = {
|
|||
};
|
||||
|
||||
template <class T, class Fun>
|
||||
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
|
||||
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot, Settings& settings)
|
||||
{
|
||||
QPushButton* btn = new QPushButton();
|
||||
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
btn->setObjectName(name);
|
||||
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
QObject::connect(btn, &QPushButton::clicked, self, onClickSlot);
|
||||
return btn;
|
||||
}
|
||||
|
@ -108,13 +108,14 @@ void setStateName(QAbstractButton* btn, State state)
|
|||
|
||||
}
|
||||
|
||||
ChatFormHeader::ChatFormHeader(QWidget* parent)
|
||||
ChatFormHeader::ChatFormHeader(Settings& settings_, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, mode{Mode::AV}
|
||||
, callState{CallButtonState::Disabled}
|
||||
, videoState{CallButtonState::Disabled}
|
||||
, volState{ToolButtonState::Disabled}
|
||||
, micState{ToolButtonState::Disabled}
|
||||
, settings{settings_}
|
||||
{
|
||||
QHBoxLayout* headLayout = new QHBoxLayout();
|
||||
avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg");
|
||||
|
@ -140,10 +141,10 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
|
|||
headTextLayout->addLayout(nameLine);
|
||||
headTextLayout->addStretch();
|
||||
|
||||
micButton = createButton("micButton", this, &ChatFormHeader::micMuteToggle);
|
||||
volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle);
|
||||
callButton = createButton("callButton", this, &ChatFormHeader::callTriggered);
|
||||
videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered);
|
||||
micButton = createButton("micButton", this, &ChatFormHeader::micMuteToggle, settings);
|
||||
volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle, settings);
|
||||
callButton = createButton("callButton", this, &ChatFormHeader::callTriggered, settings);
|
||||
videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered, settings);
|
||||
|
||||
QVBoxLayout* micButtonsLayout = new QVBoxLayout();
|
||||
micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING);
|
||||
|
@ -218,7 +219,7 @@ void ChatFormHeader::showOutgoingCall(bool video)
|
|||
void ChatFormHeader::createCallConfirm(bool video)
|
||||
{
|
||||
QWidget* btn = video ? videoButton : callButton;
|
||||
callConfirm = std::unique_ptr<CallConfirmWidget>(new CallConfirmWidget(btn));
|
||||
callConfirm = std::unique_ptr<CallConfirmWidget>(new CallConfirmWidget(settings, btn));
|
||||
connect(callConfirm.get(), &CallConfirmWidget::accepted, this, &ChatFormHeader::callAccepted);
|
||||
connect(callConfirm.get(), &CallConfirmWidget::rejected, this, &ChatFormHeader::callRejected);
|
||||
}
|
||||
|
@ -302,11 +303,11 @@ QSize ChatFormHeader::getAvatarSize() const
|
|||
|
||||
void ChatFormHeader::reloadTheme()
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet("chatArea/chatHead.css"));
|
||||
callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
micButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
setStyleSheet(Style::getStylesheet("chatArea/chatHead.css", settings));
|
||||
callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
micButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
}
|
||||
|
||||
void ChatFormHeader::addWidget(QWidget* widget, int stretch, Qt::Alignment alignment)
|
||||
|
|
|
@ -34,6 +34,7 @@ class QToolButton;
|
|||
class CallConfirmWidget;
|
||||
class QLabel;
|
||||
class ExtensionStatus;
|
||||
class Settings;
|
||||
|
||||
class ChatFormHeader : public QWidget
|
||||
{
|
||||
|
@ -58,7 +59,7 @@ public:
|
|||
AV = Audio | Video
|
||||
};
|
||||
|
||||
ChatFormHeader(QWidget* parent = nullptr);
|
||||
ChatFormHeader(Settings&, QWidget* parent = nullptr);
|
||||
~ChatFormHeader();
|
||||
|
||||
void setName(const QString& newName);
|
||||
|
@ -119,4 +120,5 @@ private:
|
|||
ToolButtonState micState;
|
||||
|
||||
std::unique_ptr<CallConfirmWidget> callConfirm;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -40,12 +40,14 @@
|
|||
|
||||
QHash<int, CircleWidget*> CircleWidget::circleList;
|
||||
|
||||
CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_)
|
||||
: CategoryWidget(isCompact(), parent)
|
||||
CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_,
|
||||
Settings& settings_)
|
||||
: CategoryWidget(isCompact(), settings_, parent)
|
||||
, id(id_)
|
||||
, core{core_}
|
||||
, settings{settings_}
|
||||
{
|
||||
setName(Settings::getInstance().getCircleName(id), false);
|
||||
setName(settings.getCircleName(id), false);
|
||||
circleList[id] = this;
|
||||
|
||||
connect(nameLabel, &CroppingLabel::editFinished, [this](const QString& newName) {
|
||||
|
@ -58,7 +60,7 @@ CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_)
|
|||
nameLabel->minimizeMaximumWidth();
|
||||
});
|
||||
|
||||
setExpanded(Settings::getInstance().getCircleExpanded(id), false);
|
||||
setExpanded(settings.getCircleExpanded(id), false);
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
|
@ -104,7 +106,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
friendList->removeCircleWidget(this);
|
||||
|
||||
int replacedCircle = Settings::getInstance().removeCircle(id);
|
||||
int replacedCircle = settings.removeCircle(id);
|
||||
|
||||
auto circleReplace = circleList.find(replacedCircle);
|
||||
if (circleReplace != circleList.end())
|
||||
|
@ -114,7 +116,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
circleList.remove(replacedCircle);
|
||||
} else if (selectedItem == openAction) {
|
||||
ContentDialog* dialog = new ContentDialog(core);
|
||||
ContentDialog* dialog = new ContentDialog(core, settings);
|
||||
emit newContentDialog(*dialog);
|
||||
for (int i = 0; i < friendOnlineLayout()->count(); ++i) {
|
||||
QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget();
|
||||
|
@ -179,11 +181,11 @@ void CircleWidget::dropEvent(QDropEvent* event)
|
|||
return;
|
||||
|
||||
// Save CircleWidget before changing the Id
|
||||
int circleId = Settings::getInstance().getFriendCircleID(toxPk);
|
||||
int circleId = settings.getFriendCircleID(toxPk);
|
||||
CircleWidget* circleWidget = getFromID(circleId);
|
||||
|
||||
addFriendWidget(widget, f->getStatus());
|
||||
Settings::getInstance().savePersonal();
|
||||
settings.savePersonal();
|
||||
|
||||
if (circleWidget != nullptr) {
|
||||
circleWidget->updateStatus();
|
||||
|
@ -194,20 +196,20 @@ void CircleWidget::dropEvent(QDropEvent* event)
|
|||
|
||||
void CircleWidget::onSetName()
|
||||
{
|
||||
Settings::getInstance().setCircleName(id, getName());
|
||||
settings.setCircleName(id, getName());
|
||||
}
|
||||
|
||||
void CircleWidget::onExpand()
|
||||
{
|
||||
Settings::getInstance().setCircleExpanded(id, isExpanded());
|
||||
Settings::getInstance().savePersonal();
|
||||
settings.setCircleExpanded(id, isExpanded());
|
||||
settings.savePersonal();
|
||||
}
|
||||
|
||||
void CircleWidget::onAddFriendWidget(FriendWidget* w)
|
||||
{
|
||||
const Friend* f = w->getFriend();
|
||||
ToxPk toxId = f->getPublicKey();
|
||||
Settings::getInstance().setFriendCircleID(toxId, id);
|
||||
settings.setFriendCircleID(toxId, id);
|
||||
}
|
||||
|
||||
void CircleWidget::updateID(int index)
|
||||
|
@ -228,7 +230,7 @@ void CircleWidget::updateID(int index)
|
|||
|
||||
if (friendWidget) {
|
||||
const Friend* f = friendWidget->getFriend();
|
||||
Settings::getInstance().setFriendCircleID(f->getPublicKey(), id);
|
||||
settings.setFriendCircleID(f->getPublicKey(), id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +240,7 @@ void CircleWidget::updateID(int index)
|
|||
|
||||
if (friendWidget) {
|
||||
const Friend* f = friendWidget->getFriend();
|
||||
Settings::getInstance().setFriendCircleID(f->getPublicKey(), id);
|
||||
settings.setFriendCircleID(f->getPublicKey(), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
|
||||
class ContentDialog;
|
||||
class Core;
|
||||
class Settings;
|
||||
|
||||
class CircleWidget final : public CategoryWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CircleWidget(const Core& core_, FriendListWidget* parent, int id_);
|
||||
CircleWidget(const Core& core_, FriendListWidget* parent, int id_, Settings&);
|
||||
~CircleWidget();
|
||||
|
||||
void editName();
|
||||
|
@ -54,4 +55,5 @@ private:
|
|||
int id;
|
||||
|
||||
const Core& core;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -53,23 +53,22 @@ const QSize minSize(minHeight, minWidget);
|
|||
const QSize defaultSize(720, 400);
|
||||
} // namespace
|
||||
|
||||
ContentDialog::ContentDialog(const Core &core, QWidget* parent)
|
||||
ContentDialog::ContentDialog(const Core &core, Settings& settings_, QWidget* parent)
|
||||
: ActivateDialog(parent, Qt::Window)
|
||||
, splitter{new QSplitter(this)}
|
||||
, friendLayout{new FriendListLayout(this)}
|
||||
, activeChatroomWidget(nullptr)
|
||||
, videoSurfaceSize(QSize())
|
||||
, videoCount(0)
|
||||
, settings{settings_}
|
||||
{
|
||||
const Settings& s = Settings::getInstance();
|
||||
|
||||
friendLayout->setMargin(0);
|
||||
friendLayout->setSpacing(0);
|
||||
|
||||
layouts = {friendLayout->getLayoutOnline(), groupLayout.getLayout(),
|
||||
friendLayout->getLayoutOffline()};
|
||||
|
||||
if (s.getGroupchatPosition()) {
|
||||
if (settings.getGroupchatPosition()) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
layouts.swapItemsAt(0, 1);
|
||||
#else
|
||||
|
@ -82,7 +81,7 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
|
|||
friendWidget->setAutoFillBackground(true);
|
||||
friendWidget->setLayout(friendLayout);
|
||||
|
||||
onGroupchatPositionChanged(s.getGroupchatPosition());
|
||||
onGroupchatPositionChanged(settings.getGroupchatPosition());
|
||||
|
||||
friendScroll = new QScrollArea(this);
|
||||
friendScroll->setMinimumWidth(minWidget);
|
||||
|
@ -95,7 +94,7 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
|
|||
QWidget* contentWidget = new QWidget(this);
|
||||
contentWidget->setAutoFillBackground(true);
|
||||
|
||||
contentLayout = new ContentLayout(contentWidget);
|
||||
contentLayout = new ContentLayout(settings, contentWidget);
|
||||
contentLayout->setMargin(0);
|
||||
contentLayout->setSpacing(0);
|
||||
|
||||
|
@ -113,7 +112,7 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
|
|||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setObjectName("detached");
|
||||
|
||||
QByteArray geometry = s.getDialogGeometry();
|
||||
QByteArray geometry = settings.getDialogGeometry();
|
||||
|
||||
if (!geometry.isNull()) {
|
||||
restoreGeometry(geometry);
|
||||
|
@ -122,7 +121,7 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
|
|||
}
|
||||
|
||||
SplitterRestorer restorer(splitter);
|
||||
restorer.restore(s.getDialogSplitterState(), size());
|
||||
restorer.restore(settings.getDialogSplitterState(), size());
|
||||
|
||||
username = core.getUsername();
|
||||
|
||||
|
@ -136,7 +135,7 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
|
|||
new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(previousContact()));
|
||||
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
|
||||
|
||||
connect(&s, &Settings::groupchatPositionChanged, this, &ContentDialog::onGroupchatPositionChanged);
|
||||
connect(&settings, &Settings::groupchatPositionChanged, this, &ContentDialog::onGroupchatPositionChanged);
|
||||
connect(splitter, &QSplitter::splitterMoved, this, &ContentDialog::saveSplitterState);
|
||||
|
||||
Translator::registerHandler(std::bind(&ContentDialog::retranslateUi, this), this);
|
||||
|
@ -155,10 +154,10 @@ void ContentDialog::closeEvent(QCloseEvent* event)
|
|||
|
||||
FriendWidget* ContentDialog::addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form)
|
||||
{
|
||||
const auto compact = Settings::getInstance().getCompactLayout();
|
||||
const auto compact = settings.getCompactLayout();
|
||||
auto frnd = chatroom->getFriend();
|
||||
const auto& friendPk = frnd->getPublicKey();
|
||||
auto friendWidget = new FriendWidget(chatroom, compact);
|
||||
auto friendWidget = new FriendWidget(chatroom, compact, settings);
|
||||
emit connectFriendWidget(*friendWidget);
|
||||
contactWidgets[friendPk] = friendWidget;
|
||||
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
|
||||
|
@ -179,8 +178,8 @@ GroupWidget* ContentDialog::addGroup(std::shared_ptr<GroupChatroom> chatroom, Ge
|
|||
{
|
||||
const auto g = chatroom->getGroup();
|
||||
const auto& groupId = g->getPersistentId();
|
||||
const auto compact = Settings::getInstance().getCompactLayout();
|
||||
auto groupWidget = new GroupWidget(chatroom, compact);
|
||||
const auto compact = settings.getCompactLayout();
|
||||
auto groupWidget = new GroupWidget(chatroom, compact, settings);
|
||||
contactWidgets[groupId] = groupWidget;
|
||||
groupLayout.addSortedWidget(groupWidget);
|
||||
contactChatForms[groupId] = form;
|
||||
|
@ -312,7 +311,7 @@ void ContentDialog::cycleContacts(bool forward, bool inverse)
|
|||
}
|
||||
|
||||
if (!inverse && index == currentLayout->count() - 1) {
|
||||
bool groupsOnTop = Settings::getInstance().getGroupchatPosition();
|
||||
bool groupsOnTop = settings.getGroupchatPosition();
|
||||
bool offlineEmpty = friendLayout->getLayoutOffline()->isEmpty();
|
||||
bool onlineEmpty = friendLayout->getLayoutOnline()->isEmpty();
|
||||
bool groupsEmpty = groupLayout.getLayout()->isEmpty();
|
||||
|
@ -439,8 +438,8 @@ void ContentDialog::setUsername(const QString& newName)
|
|||
|
||||
void ContentDialog::reloadTheme()
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet("contentDialog/contentDialog.css"));
|
||||
friendScroll->setStyleSheet(Style::getStylesheet("friendList/friendList.css"));
|
||||
setStyleSheet(Style::getStylesheet("contentDialog/contentDialog.css", settings));
|
||||
friendScroll->setStyleSheet(Style::getStylesheet("friendList/friendList.css", settings));
|
||||
}
|
||||
|
||||
bool ContentDialog::event(QEvent* event)
|
||||
|
@ -677,7 +676,7 @@ void ContentDialog::retranslateUi()
|
|||
*/
|
||||
void ContentDialog::saveDialogGeometry()
|
||||
{
|
||||
Settings::getInstance().setDialogGeometry(saveGeometry());
|
||||
settings.setDialogGeometry(saveGeometry());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -685,7 +684,7 @@ void ContentDialog::saveDialogGeometry()
|
|||
*/
|
||||
void ContentDialog::saveSplitterState()
|
||||
{
|
||||
Settings::getInstance().setDialogSplitterState(splitter->saveState());
|
||||
settings.setDialogSplitterState(splitter->saveState());
|
||||
}
|
||||
|
||||
bool ContentDialog::hasContact(const ContactId& contactId) const
|
||||
|
|
|
@ -45,12 +45,13 @@ class GroupWidget;
|
|||
class QCloseEvent;
|
||||
class QSplitter;
|
||||
class QScrollArea;
|
||||
class Settings;
|
||||
|
||||
class ContentDialog : public ActivateDialog, public IDialogs
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ContentDialog(const Core& core, QWidget* parent = nullptr);
|
||||
ContentDialog(const Core& core, Settings&, QWidget* parent = nullptr);
|
||||
~ContentDialog() override;
|
||||
|
||||
FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);
|
||||
|
@ -135,4 +136,5 @@ private:
|
|||
QHash<const ContactId&, GenericChatForm*> contactChatForms;
|
||||
|
||||
QString username;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -24,14 +24,16 @@
|
|||
#include <QFrame>
|
||||
#include <QStyleFactory>
|
||||
|
||||
ContentLayout::ContentLayout()
|
||||
ContentLayout::ContentLayout(Settings& settings_)
|
||||
: QVBoxLayout()
|
||||
, settings{settings_}
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
ContentLayout::ContentLayout(QWidget* parent)
|
||||
ContentLayout::ContentLayout(Settings& settings_, QWidget* parent)
|
||||
: QVBoxLayout(parent)
|
||||
, settings{settings_}
|
||||
{
|
||||
init();
|
||||
|
||||
|
@ -70,8 +72,8 @@ ContentLayout::~ContentLayout()
|
|||
void ContentLayout::reloadTheme()
|
||||
{
|
||||
#ifndef Q_OS_MAC
|
||||
mainHead->setStyleSheet(Style::getStylesheet("settings/mainHead.css"));
|
||||
mainContent->setStyleSheet(Style::getStylesheet("window/general.css"));
|
||||
mainHead->setStyleSheet(Style::getStylesheet("settings/mainHead.css", settings));
|
||||
mainContent->setStyleSheet(Style::getStylesheet("window/general.css", settings));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -113,10 +115,10 @@ void ContentLayout::init()
|
|||
mainContent->setLayout(new QVBoxLayout);
|
||||
mainContent->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
if (QStyleFactory::keys().contains(Settings::getInstance().getStyle())
|
||||
&& Settings::getInstance().getStyle() != "None") {
|
||||
mainHead->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
|
||||
mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
|
||||
if (QStyleFactory::keys().contains(settings.getStyle())
|
||||
&& settings.getStyle() != "None") {
|
||||
mainHead->setStyle(QStyleFactory::create(settings.getStyle()));
|
||||
mainContent->setStyle(QStyleFactory::create(settings.getStyle()));
|
||||
}
|
||||
|
||||
connect(&GUI::getInstance(), &GUI::themeReload, this, &ContentLayout::reloadTheme);
|
||||
|
|
|
@ -22,11 +22,13 @@
|
|||
#include <QBoxLayout>
|
||||
#include <QFrame>
|
||||
|
||||
class Settings;
|
||||
|
||||
class ContentLayout : public QVBoxLayout
|
||||
{
|
||||
public:
|
||||
ContentLayout();
|
||||
explicit ContentLayout(QWidget* parent);
|
||||
ContentLayout(Settings&);
|
||||
explicit ContentLayout(Settings&, QWidget* parent);
|
||||
~ContentLayout();
|
||||
|
||||
void clear();
|
||||
|
@ -35,6 +37,7 @@ public:
|
|||
QHBoxLayout mainHLineLayout;
|
||||
QWidget* mainContent;
|
||||
QWidget* mainHead;
|
||||
Settings& settings;
|
||||
|
||||
public slots:
|
||||
void reloadTheme();
|
||||
|
|
|
@ -31,10 +31,11 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
EmoticonsWidget::EmoticonsWidget(SmileyPack& smileyPack, QWidget* parent)
|
||||
EmoticonsWidget::EmoticonsWidget(SmileyPack& smileyPack, Settings& settings,
|
||||
QWidget* parent)
|
||||
: QMenu(parent)
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet("emoticonWidget/emoticonWidget.css"));
|
||||
setStyleSheet(Style::getStylesheet("emoticonWidget/emoticonWidget.css", settings));
|
||||
setLayout(&layout);
|
||||
layout.addWidget(&stack);
|
||||
|
||||
|
@ -57,7 +58,7 @@ EmoticonsWidget::EmoticonsWidget(SmileyPack& smileyPack, QWidget* parent)
|
|||
int col = 0;
|
||||
|
||||
// respect configured emoticon size
|
||||
const int px = Settings::getInstance().getEmojiFontPointSize();
|
||||
const int px = settings.getEmojiFontPointSize();
|
||||
const QSize size(px, px);
|
||||
|
||||
// create pages
|
||||
|
|
|
@ -28,12 +28,13 @@
|
|||
|
||||
class QIcon;
|
||||
class SmileyPack;
|
||||
class Settings;
|
||||
|
||||
class EmoticonsWidget : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EmoticonsWidget(SmileyPack&, QWidget* parent = nullptr);
|
||||
EmoticonsWidget(SmileyPack&, Settings&, QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void insertEmoticon(QString str);
|
||||
|
|
|
@ -61,8 +61,9 @@ namespace
|
|||
* @brief Cached username so we can retranslate the invite message
|
||||
*/
|
||||
|
||||
AddFriendForm::AddFriendForm(ToxId _ownId)
|
||||
: ownId{_ownId}
|
||||
AddFriendForm::AddFriendForm(ToxId ownId_, Settings& settings_)
|
||||
: ownId{ownId_}
|
||||
, settings{settings_}
|
||||
{
|
||||
tabWidget = new QTabWidget();
|
||||
main = new QWidget(tabWidget);
|
||||
|
@ -122,9 +123,9 @@ AddFriendForm::AddFriendForm(ToxId _ownId)
|
|||
retranslateUi();
|
||||
Translator::registerHandler(std::bind(&AddFriendForm::retranslateUi, this), this);
|
||||
|
||||
const int size = Settings::getInstance().getFriendRequestSize();
|
||||
const int size = settings.getFriendRequestSize();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
Settings::Request request = Settings::getInstance().getFriendRequest(i);
|
||||
Settings::Request request = settings.getFriendRequest(i);
|
||||
addFriendRequestWidget(request.address, request.message);
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ void AddFriendForm::setMode(Mode mode)
|
|||
|
||||
bool AddFriendForm::addFriendRequest(const QString& friendAddress, const QString& message_)
|
||||
{
|
||||
if (Settings::getInstance().addFriendRequest(friendAddress, message_)) {
|
||||
if (settings.addFriendRequest(friendAddress, message_)) {
|
||||
addFriendRequestWidget(friendAddress, message_);
|
||||
if (isShown()) {
|
||||
onCurrentChanged(tabWidget->currentIndex());
|
||||
|
@ -292,7 +293,7 @@ void AddFriendForm::onIdChanged(const QString& id)
|
|||
isValidId ? QStringLiteral("%1 (%2)") : QStringLiteral("%1 <font color='red'>(%2)</font>");
|
||||
toxIdLabel.setText(labelText.arg(toxIdText, toxIdComment));
|
||||
toxId.setStyleSheet(isValidOrEmpty ? QStringLiteral("")
|
||||
: Style::getStylesheet("addFriendForm/toxId.css"));
|
||||
: Style::getStylesheet("addFriendForm/toxId.css", settings));
|
||||
toxId.setToolTip(isValidOrEmpty ? QStringLiteral("") : tr("Invalid Tox ID format"));
|
||||
|
||||
sendButton.setEnabled(isValidId);
|
||||
|
@ -311,11 +312,11 @@ void AddFriendForm::setIdFromClipboard()
|
|||
|
||||
void AddFriendForm::deleteFriendRequest(const ToxId& toxId_)
|
||||
{
|
||||
const int size = Settings::getInstance().getFriendRequestSize();
|
||||
const int size = settings.getFriendRequestSize();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
Settings::Request request = Settings::getInstance().getFriendRequest(i);
|
||||
Settings::Request request = settings.getFriendRequest(i);
|
||||
if (toxId_.getPublicKey() == ToxPk(request.address)) {
|
||||
Settings::getInstance().removeFriendRequest(i);
|
||||
settings.removeFriendRequest(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -328,10 +329,10 @@ void AddFriendForm::onFriendRequestAccepted()
|
|||
const int index = requestsLayout->indexOf(friendWidget);
|
||||
removeFriendRequestWidget(friendWidget);
|
||||
const int indexFromEnd = requestsLayout->count() - index - 1;
|
||||
const Settings::Request request = Settings::getInstance().getFriendRequest(indexFromEnd);
|
||||
const Settings::Request request = settings.getFriendRequest(indexFromEnd);
|
||||
emit friendRequestAccepted(ToxPk{request.address});
|
||||
Settings::getInstance().removeFriendRequest(indexFromEnd);
|
||||
Settings::getInstance().savePersonal();
|
||||
settings.removeFriendRequest(indexFromEnd);
|
||||
settings.savePersonal();
|
||||
}
|
||||
|
||||
void AddFriendForm::onFriendRequestRejected()
|
||||
|
@ -341,15 +342,15 @@ void AddFriendForm::onFriendRequestRejected()
|
|||
const int index = requestsLayout->indexOf(friendWidget);
|
||||
removeFriendRequestWidget(friendWidget);
|
||||
const int indexFromEnd = requestsLayout->count() - index - 1;
|
||||
Settings::getInstance().removeFriendRequest(indexFromEnd);
|
||||
Settings::getInstance().savePersonal();
|
||||
settings.removeFriendRequest(indexFromEnd);
|
||||
settings.savePersonal();
|
||||
}
|
||||
|
||||
void AddFriendForm::onCurrentChanged(int index)
|
||||
{
|
||||
if (index == FriendRequest && Settings::getInstance().getUnreadFriendRequests() != 0) {
|
||||
Settings::getInstance().clearUnreadFriendRequests();
|
||||
Settings::getInstance().savePersonal();
|
||||
if (index == FriendRequest && settings.getUnreadFriendRequests() != 0) {
|
||||
settings.clearUnreadFriendRequests();
|
||||
settings.savePersonal();
|
||||
emit friendRequestsSeen();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
class QTabWidget;
|
||||
|
||||
class ContentLayout;
|
||||
class Settings;
|
||||
|
||||
class AddFriendForm : public QObject
|
||||
{
|
||||
|
@ -45,7 +46,7 @@ public:
|
|||
FriendRequest = 2
|
||||
};
|
||||
|
||||
AddFriendForm(ToxId _ownId);
|
||||
AddFriendForm(ToxId ownId_, Settings&);
|
||||
AddFriendForm(const AddFriendForm&) = delete;
|
||||
AddFriendForm& operator=(const AddFriendForm&) = delete;
|
||||
~AddFriendForm();
|
||||
|
@ -113,4 +114,5 @@ private:
|
|||
QList<QString> contactsToImport;
|
||||
|
||||
ToxId ownId;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -108,14 +108,15 @@ QString secondsToDHMS(quint32 duration)
|
|||
|
||||
ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache_,
|
||||
SmileyPack& smileyPack_, CameraSource& cameraSource_)
|
||||
SmileyPack& smileyPack_, CameraSource& cameraSource_, Settings& settings_)
|
||||
: GenericChatForm(profile.getCore(), chatFriend, chatLog_, messageDispatcher_,
|
||||
documentCache_, smileyPack_)
|
||||
documentCache_, smileyPack_, settings_)
|
||||
, core{profile.getCore()}
|
||||
, f(chatFriend)
|
||||
, isTyping{false}
|
||||
, lastCallIsVideo{false}
|
||||
, cameraSource{cameraSource_}
|
||||
, settings{settings_}
|
||||
{
|
||||
setName(f->getDisplayedName());
|
||||
|
||||
|
@ -146,7 +147,7 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
|
|||
imagePreview->setStyleSheet("QPushButton { border: 0px }");
|
||||
imagePreview->hide();
|
||||
|
||||
auto cancelIcon = QIcon(Style::getImagePath("rejectCall/rejectCall.svg"));
|
||||
auto cancelIcon = QIcon(Style::getImagePath("rejectCall/rejectCall.svg", settings));
|
||||
QPushButton* cancelButton = new QPushButton(imagePreview);
|
||||
cancelButton->setFixedSize(20, 20);
|
||||
cancelButton->move(QPoint(80, 0));
|
||||
|
@ -258,7 +259,7 @@ void ChatForm::onExtensionSupportChanged(ExtensionSet extensions)
|
|||
|
||||
void ChatForm::onTextEditChanged()
|
||||
{
|
||||
if (!Settings::getInstance().getTypingNotification()) {
|
||||
if (!settings.getTypingNotification()) {
|
||||
if (isTyping) {
|
||||
isTyping = false;
|
||||
core.sendTyping(f->getId(), false);
|
||||
|
@ -323,7 +324,7 @@ void ChatForm::onAvInvite(uint32_t friendId, bool video)
|
|||
|
||||
auto testedFlag = video ? Settings::AutoAcceptCall::Video : Settings::AutoAcceptCall::Audio;
|
||||
// AutoAcceptCall is set for this friend
|
||||
if (Settings::getInstance().getAutoAcceptCall(f->getPublicKey()).testFlag(testedFlag)) {
|
||||
if (settings.getAutoAcceptCall(f->getPublicKey()).testFlag(testedFlag)) {
|
||||
qDebug() << "automatic call answer";
|
||||
CoreAV* coreav = core.getAv();
|
||||
QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection,
|
||||
|
@ -470,7 +471,7 @@ void ChatForm::onFriendStatusChanged(const ToxPk& friendPk, Status::Status statu
|
|||
|
||||
updateCallButtons();
|
||||
|
||||
if (Settings::getInstance().getStatusChangeNotificationEnabled()) {
|
||||
if (settings.getStatusChangeNotificationEnabled()) {
|
||||
QString fStatus = Status::getTitle(status);
|
||||
addSystemInfoMessage(QDateTime::currentDateTime(), SystemMessageType::peerStateChange,
|
||||
{f->getDisplayedName(), fStatus});
|
||||
|
@ -511,7 +512,8 @@ std::unique_ptr<NetCamView> ChatForm::createNetcam()
|
|||
{
|
||||
qDebug() << "creating netcam";
|
||||
uint32_t friendId = f->getId();
|
||||
std::unique_ptr<NetCamView> view = std::unique_ptr<NetCamView>(new NetCamView(f->getPublicKey(), cameraSource, this));
|
||||
std::unique_ptr<NetCamView> view = std::unique_ptr<NetCamView>(
|
||||
new NetCamView(f->getPublicKey(), cameraSource, settings, this));
|
||||
CoreAV* av = core.getAv();
|
||||
VideoSource* source = av->getVideoSourceFromCall(friendId);
|
||||
view->show(source, f->getDisplayedName());
|
||||
|
@ -610,14 +612,14 @@ void ChatForm::sendImageFromPreview()
|
|||
return;
|
||||
}
|
||||
|
||||
QDir(Settings::getInstance().getPaths().getAppDataDirPath()).mkpath("images");
|
||||
QDir(settings.getPaths().getAppDataDirPath()).mkpath("images");
|
||||
|
||||
// use ~ISO 8601 for screenshot timestamp, considering FS limitations
|
||||
// https://en.wikipedia.org/wiki/ISO_8601
|
||||
// Windows has to be supported, thus filename can't have `:` in it :/
|
||||
// Format should be: `qTox_Screenshot_yyyy-MM-dd HH-mm-ss.zzz.png`
|
||||
QString filepath = QString("%1images%2qTox_Image_%3.png")
|
||||
.arg(Settings::getInstance().getPaths().getAppDataDirPath())
|
||||
.arg(settings.getPaths().getAppDataDirPath())
|
||||
.arg(QDir::separator())
|
||||
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH-mm-ss.zzz"));
|
||||
QFile file(filepath);
|
||||
|
|
|
@ -44,6 +44,7 @@ class QMoveEvent;
|
|||
class ImagePreviewButton;
|
||||
class DocumentCache;
|
||||
class SmileyPack;
|
||||
class Settings;
|
||||
|
||||
class ChatForm : public GenericChatForm
|
||||
{
|
||||
|
@ -51,7 +52,7 @@ class ChatForm : public GenericChatForm
|
|||
public:
|
||||
ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache&, SmileyPack&,
|
||||
CameraSource&);
|
||||
CameraSource&, Settings&);
|
||||
~ChatForm() override;
|
||||
void setStatusMessage(const QString& newMessage);
|
||||
|
||||
|
@ -143,4 +144,5 @@ private:
|
|||
bool lastCallIsVideo;
|
||||
std::unique_ptr<NetCamView> netcam;
|
||||
CameraSource& cameraSource;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -324,8 +324,9 @@ namespace FileTransferList
|
|||
return true;
|
||||
}
|
||||
|
||||
Delegate::Delegate(QWidget* parent)
|
||||
Delegate::Delegate(Settings& settings_, QWidget* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
, settings{settings_}
|
||||
{}
|
||||
|
||||
void Delegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
|
@ -358,11 +359,11 @@ namespace FileTransferList
|
|||
}
|
||||
const auto localPaused = data.toBool();
|
||||
QPixmap pausePixmap = localPaused
|
||||
? QPixmap(Style::getImagePath("fileTransferInstance/arrow_black.svg"))
|
||||
: QPixmap(Style::getImagePath("fileTransferInstance/pause_dark.svg"));
|
||||
? QPixmap(Style::getImagePath("fileTransferInstance/arrow_black.svg", settings))
|
||||
: QPixmap(Style::getImagePath("fileTransferInstance/pause_dark.svg", settings));
|
||||
QApplication::style()->drawItemPixmap(painter, pauseRect(option), Qt::AlignCenter, pausePixmap);
|
||||
|
||||
QPixmap stopPixmap(Style::getImagePath("fileTransferInstance/no_dark.svg"));
|
||||
QPixmap stopPixmap(Style::getImagePath("fileTransferInstance/no_dark.svg", settings));
|
||||
QApplication::style()->drawItemPixmap(painter, stopRect(option), Qt::AlignCenter, stopPixmap);
|
||||
return;
|
||||
}
|
||||
|
@ -401,7 +402,7 @@ namespace FileTransferList
|
|||
}
|
||||
|
||||
|
||||
View::View(QAbstractItemModel* model, QWidget* parent)
|
||||
View::View(QAbstractItemModel* model, Settings& settings, QWidget* parent)
|
||||
: QTableView(parent)
|
||||
{
|
||||
setModel(model);
|
||||
|
@ -416,14 +417,14 @@ namespace FileTransferList
|
|||
setShowGrid(false);
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
setItemDelegate(new Delegate(this));
|
||||
setItemDelegate(new Delegate(settings, this));
|
||||
}
|
||||
|
||||
View::~View() = default;
|
||||
|
||||
} // namespace FileTransferList
|
||||
|
||||
FilesForm::FilesForm(CoreFile& coreFile)
|
||||
FilesForm::FilesForm(CoreFile& coreFile, Settings& settings)
|
||||
: QObject()
|
||||
{
|
||||
head = new QWidget();
|
||||
|
@ -453,8 +454,8 @@ FilesForm::FilesForm(CoreFile& coreFile)
|
|||
connect(sentModel, &FileTransferList::Model::togglePause, pauseFile);
|
||||
connect(sentModel, &FileTransferList::Model::cancel, cancelFileSend);
|
||||
|
||||
recvd = new FileTransferList::View(recvdModel);
|
||||
sent = new FileTransferList::View(sentModel);
|
||||
recvd = new FileTransferList::View(recvdModel, settings);
|
||||
sent = new FileTransferList::View(sentModel, settings);
|
||||
|
||||
main.addTab(recvd, QString());
|
||||
main.addTab(sent, QString());
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
class ContentLayout;
|
||||
class QTableView;
|
||||
class Settings;
|
||||
|
||||
namespace FileTransferList
|
||||
{
|
||||
|
@ -88,16 +89,18 @@ namespace FileTransferList
|
|||
class Delegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
Delegate(QWidget* parent = nullptr);
|
||||
Delegate(Settings&, QWidget* parent = nullptr);
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
|
||||
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
|
||||
private:
|
||||
Settings& settings;
|
||||
};
|
||||
|
||||
class View : public QTableView
|
||||
{
|
||||
public:
|
||||
View(QAbstractItemModel* model, QWidget* parent = nullptr);
|
||||
View(QAbstractItemModel* model, Settings&, QWidget* parent = nullptr);
|
||||
~View();
|
||||
|
||||
};
|
||||
|
@ -108,7 +111,7 @@ class FilesForm : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FilesForm(CoreFile& coreFile);
|
||||
FilesForm(CoreFile& coreFile, Settings&);
|
||||
~FilesForm();
|
||||
|
||||
bool isShown() const;
|
||||
|
|
|
@ -121,7 +121,7 @@ namespace
|
|||
{
|
||||
|
||||
template <class T, class Fun>
|
||||
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
|
||||
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot, Settings& settings)
|
||||
{
|
||||
QPushButton* btn = new QPushButton();
|
||||
// Fix for incorrect layouts on OS X as per
|
||||
|
@ -129,7 +129,7 @@ QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
|
|||
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
btn->setObjectName(name);
|
||||
btn->setProperty("state", "green");
|
||||
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
QObject::connect(btn, &QPushButton::clicked, self, onClickSlot);
|
||||
return btn;
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
|
|||
|
||||
GenericChatForm::GenericChatForm(const Core& core_, const Contact* contact, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
|
||||
SmileyPack& smileyPack_, QWidget* parent_)
|
||||
SmileyPack& smileyPack_, Settings& settings_, QWidget* parent_)
|
||||
: QWidget(parent_, Qt::Window)
|
||||
, core{core_}
|
||||
, audioInputFlag(false)
|
||||
|
@ -146,33 +146,34 @@ GenericChatForm::GenericChatForm(const Core& core_, const Contact* contact, ICha
|
|||
, chatLog(chatLog_)
|
||||
, messageDispatcher(messageDispatcher_)
|
||||
, smileyPack{smileyPack_}
|
||||
, settings{settings_}
|
||||
{
|
||||
curRow = 0;
|
||||
headWidget = new ChatFormHeader();
|
||||
searchForm = new SearchForm();
|
||||
headWidget = new ChatFormHeader(settings);
|
||||
searchForm = new SearchForm(settings);
|
||||
dateInfo = new QLabel(this);
|
||||
chatWidget = new ChatWidget(chatLog_, core, documentCache, smileyPack, this);
|
||||
chatWidget = new ChatWidget(chatLog_, core, documentCache, smileyPack,
|
||||
settings, this);
|
||||
searchForm->hide();
|
||||
dateInfo->setAlignment(Qt::AlignHCenter);
|
||||
dateInfo->setVisible(false);
|
||||
|
||||
// settings
|
||||
const Settings& s = Settings::getInstance();
|
||||
connect(&s, &Settings::emojiFontPointSizeChanged, chatWidget, &ChatWidget::forceRelayout);
|
||||
connect(&s, &Settings::chatMessageFontChanged, this, &GenericChatForm::onChatMessageFontChanged);
|
||||
connect(&settings, &Settings::emojiFontPointSizeChanged, chatWidget, &ChatWidget::forceRelayout);
|
||||
connect(&settings, &Settings::chatMessageFontChanged, this, &GenericChatForm::onChatMessageFontChanged);
|
||||
|
||||
msgEdit = new ChatTextEdit();
|
||||
#ifdef SPELL_CHECKING
|
||||
if (s.getSpellCheckingEnabled()) {
|
||||
if (settings.getSpellCheckingEnabled()) {
|
||||
decorator = new Sonnet::SpellCheckDecorator(msgEdit);
|
||||
}
|
||||
#endif
|
||||
|
||||
sendButton = createButton("sendButton", this, &GenericChatForm::onSendTriggered);
|
||||
emoteButton = createButton("emoteButton", this, &GenericChatForm::onEmoteButtonClicked);
|
||||
sendButton = createButton("sendButton", this, &GenericChatForm::onSendTriggered, settings);
|
||||
emoteButton = createButton("emoteButton", this, &GenericChatForm::onEmoteButtonClicked, settings);
|
||||
|
||||
fileButton = createButton("fileButton", this, &GenericChatForm::onAttachClicked);
|
||||
screenshotButton = createButton("screenshotButton", this, &GenericChatForm::onScreenshotClicked);
|
||||
fileButton = createButton("fileButton", this, &GenericChatForm::onAttachClicked, settings);
|
||||
screenshotButton = createButton("screenshotButton", this, &GenericChatForm::onScreenshotClicked, settings);
|
||||
|
||||
// TODO: Make updateCallButtons (see ChatForm) abstract
|
||||
// and call here to set tooltips.
|
||||
|
@ -351,15 +352,14 @@ QDateTime GenericChatForm::getLatestTime() const
|
|||
|
||||
void GenericChatForm::reloadTheme()
|
||||
{
|
||||
const Settings& s = Settings::getInstance();
|
||||
setStyleSheet(Style::getStylesheet("genericChatForm/genericChatForm.css"));
|
||||
msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css")
|
||||
+ fontToCss(s.getChatMessageFont(), "QTextEdit"));
|
||||
setStyleSheet(Style::getStylesheet("genericChatForm/genericChatForm.css", settings));
|
||||
msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css", settings)
|
||||
+ fontToCss(settings.getChatMessageFont(), "QTextEdit"));
|
||||
|
||||
emoteButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
sendButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
emoteButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
sendButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
|
||||
}
|
||||
|
||||
void GenericChatForm::setName(const QString& newName)
|
||||
|
@ -456,7 +456,7 @@ void GenericChatForm::onEmoteButtonClicked()
|
|||
if (smileyPack.getEmoticons().empty())
|
||||
return;
|
||||
|
||||
EmoticonsWidget widget(smileyPack);
|
||||
EmoticonsWidget widget(smileyPack, settings);
|
||||
connect(&widget, SIGNAL(insertEmoticon(QString)), this, SLOT(onEmoteInsertRequested(QString)));
|
||||
widget.installEventFilter(this);
|
||||
|
||||
|
@ -494,7 +494,7 @@ void GenericChatForm::onChatMessageFontChanged(const QFont& font)
|
|||
chatWidget->fontChanged(font);
|
||||
chatWidget->forceRelayout();
|
||||
// message editor
|
||||
msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css")
|
||||
msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css", settings)
|
||||
+ fontToCss(font, "QTextEdit"));
|
||||
}
|
||||
|
||||
|
@ -708,7 +708,7 @@ void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& prevLine, const Ch
|
|||
const auto date = getTime(effectiveTopLine);
|
||||
|
||||
if (date.isValid() && date.date() != QDate::currentDate()) {
|
||||
const auto dateText = QStringLiteral("<b>%1<\b>").arg(date.toString(Settings::getInstance().getDateFormat()));
|
||||
const auto dateText = QStringLiteral("<b>%1<\b>").arg(date.toString(settings.getDateFormat()));
|
||||
dateInfo->setText(dateText);
|
||||
dateInfo->setVisible(true);
|
||||
} else {
|
||||
|
|
|
@ -55,6 +55,7 @@ class IMessageDispatcher;
|
|||
struct Message;
|
||||
class DocumentCache;
|
||||
class SmileyPack;
|
||||
class Settings;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -72,7 +73,7 @@ class GenericChatForm : public QWidget
|
|||
public:
|
||||
GenericChatForm(const Core& core_, const Contact* contact, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache&,
|
||||
SmileyPack&, QWidget* parent_ = nullptr);
|
||||
SmileyPack&, Settings&, QWidget* parent_ = nullptr);
|
||||
~GenericChatForm() override;
|
||||
|
||||
void setName(const QString& newName);
|
||||
|
@ -169,4 +170,5 @@ protected:
|
|||
IChatLog& chatLog;
|
||||
IMessageDispatcher& messageDispatcher;
|
||||
SmileyPack& smileyPack;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "src/widget/tool/croppinglabel.h"
|
||||
#include "src/widget/translator.h"
|
||||
#include "src/persistence/igroupsettings.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
|
@ -83,9 +84,9 @@ QString editName(const QString& name)
|
|||
*/
|
||||
|
||||
GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, IGroupSettings& settings_, DocumentCache& documentCache_,
|
||||
IMessageDispatcher& messageDispatcher_, Settings& settings_, DocumentCache& documentCache_,
|
||||
SmileyPack& smileyPack_)
|
||||
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_, documentCache_, smileyPack_)
|
||||
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_, documentCache_, smileyPack_, settings_)
|
||||
, core{core_}
|
||||
, group(chatGroup)
|
||||
, inCall(false)
|
||||
|
@ -216,7 +217,7 @@ void GroupChatForm::updateUserNames()
|
|||
label->setProperty("peerType", LABEL_PEER_TYPE_MUTED);
|
||||
}
|
||||
|
||||
label->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH));
|
||||
label->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
|
||||
peerLabels.insert(peerPk, label);
|
||||
}
|
||||
|
||||
|
@ -285,7 +286,7 @@ void GroupChatForm::peerAudioPlaying(ToxPk peerPk)
|
|||
});
|
||||
}
|
||||
|
||||
peerLabels[peerPk]->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH));
|
||||
peerLabels[peerPk]->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
|
||||
peerAudioTimers[peerPk]->start(500);
|
||||
}
|
||||
|
||||
|
@ -433,7 +434,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
|
|||
} else {
|
||||
toggleMuteAction = contextMenu->addAction(muteString);
|
||||
}
|
||||
contextMenu->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH));
|
||||
contextMenu->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
|
||||
|
||||
const QAction* selectedItem = contextMenu->exec(pos);
|
||||
if (selectedItem == toggleMuteAction) {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "genericchatform.h"
|
||||
#include "src/core/toxpk.h"
|
||||
#include "src/persistence/igroupsettings.h"
|
||||
#include <QMap>
|
||||
|
||||
namespace Ui {
|
||||
|
@ -34,7 +35,6 @@ class GroupId;
|
|||
class IMessageDispatcher;
|
||||
struct Message;
|
||||
class Settings;
|
||||
class IGroupSettings;
|
||||
class DocumentCache;
|
||||
class SmileyPack;
|
||||
|
||||
|
@ -43,7 +43,7 @@ class GroupChatForm : public GenericChatForm
|
|||
Q_OBJECT
|
||||
public:
|
||||
GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, IGroupSettings& settings_,
|
||||
IMessageDispatcher& messageDispatcher_, Settings& settings_,
|
||||
DocumentCache&, SmileyPack&);
|
||||
~GroupChatForm();
|
||||
|
||||
|
@ -84,5 +84,5 @@ private:
|
|||
QLabel* nusersLabel;
|
||||
TabCompleter* tabber;
|
||||
bool inCall;
|
||||
IGroupSettings& settings;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -45,12 +45,13 @@
|
|||
* @brief This form contains all group invites you received
|
||||
*/
|
||||
|
||||
GroupInviteForm::GroupInviteForm()
|
||||
GroupInviteForm::GroupInviteForm(Settings& settings_)
|
||||
: headWidget(new QWidget(this))
|
||||
, headLabel(new QLabel(this))
|
||||
, createButton(new QPushButton(this))
|
||||
, inviteBox(new QGroupBox(this))
|
||||
, scroll(new QScrollArea(this))
|
||||
, settings{settings_}
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
connect(createButton, &QPushButton::clicked,
|
||||
|
@ -123,7 +124,7 @@ bool GroupInviteForm::addGroupInvite(const GroupInvite& inviteInfo)
|
|||
}
|
||||
}
|
||||
|
||||
GroupInviteWidget* widget = new GroupInviteWidget(this, inviteInfo);
|
||||
GroupInviteWidget* widget = new GroupInviteWidget(this, inviteInfo, settings);
|
||||
scroll->widget()->layout()->addWidget(widget);
|
||||
invites.append(widget);
|
||||
connect(widget, &GroupInviteWidget::accepted, [this] (const GroupInvite& inviteInfo_) {
|
||||
|
|
|
@ -32,6 +32,7 @@ class QLabel;
|
|||
class QPushButton;
|
||||
class QScrollArea;
|
||||
class QSignalMapper;
|
||||
class Settings;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -41,7 +42,7 @@ class GroupInviteForm : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GroupInviteForm();
|
||||
explicit GroupInviteForm(Settings&);
|
||||
~GroupInviteForm();
|
||||
|
||||
void show(ContentLayout* contentLayout);
|
||||
|
@ -67,4 +68,5 @@ private:
|
|||
QGroupBox* inviteBox;
|
||||
QList<GroupInviteWidget*> invites;
|
||||
QScrollArea* scroll;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -35,13 +35,14 @@
|
|||
* and provides buttons to accept/reject it
|
||||
*/
|
||||
|
||||
GroupInviteWidget::GroupInviteWidget(QWidget* parent, const GroupInvite& invite)
|
||||
GroupInviteWidget::GroupInviteWidget(QWidget* parent, const GroupInvite& invite, Settings& settings_)
|
||||
: QWidget(parent)
|
||||
, acceptButton(new QPushButton(this))
|
||||
, rejectButton(new QPushButton(this))
|
||||
, inviteMessageLabel(new CroppingLabel(this))
|
||||
, widgetLayout(new QHBoxLayout(this))
|
||||
, inviteInfo(invite)
|
||||
, settings{settings_}
|
||||
{
|
||||
connect(acceptButton, &QPushButton::clicked, [=]() { emit accepted(inviteInfo); });
|
||||
connect(rejectButton, &QPushButton::clicked, [=]() { emit rejected(inviteInfo); });
|
||||
|
@ -59,8 +60,8 @@ void GroupInviteWidget::retranslateUi()
|
|||
{
|
||||
QString name = Nexus::getCore()->getFriendUsername(inviteInfo.getFriendId());
|
||||
QDateTime inviteDate = inviteInfo.getInviteDate();
|
||||
QString date = inviteDate.toString(Settings::getInstance().getDateFormat());
|
||||
QString time = inviteDate.toString(Settings::getInstance().getTimestampFormat());
|
||||
QString date = inviteDate.toString(settings.getDateFormat());
|
||||
QString time = inviteDate.toString(settings.getTimestampFormat());
|
||||
|
||||
inviteMessageLabel->setText(
|
||||
tr("Invited by %1 on %2 at %3.").arg("<b>%1</b>").arg(name.toHtmlEscaped(), date, time));
|
||||
|
|
|
@ -27,12 +27,13 @@ class CroppingLabel;
|
|||
|
||||
class QHBoxLayout;
|
||||
class QPushButton;
|
||||
class Settings;
|
||||
|
||||
class GroupInviteWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GroupInviteWidget(QWidget* parent, const GroupInvite& invite);
|
||||
GroupInviteWidget(QWidget* parent, const GroupInvite& invite, Settings&);
|
||||
void retranslateUi();
|
||||
const GroupInvite getInviteInfo() const;
|
||||
|
||||
|
@ -46,4 +47,5 @@ private:
|
|||
CroppingLabel* inviteMessageLabel;
|
||||
QHBoxLayout* widgetLayout;
|
||||
GroupInvite inviteInfo;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -99,10 +99,12 @@ const QPair<QString, QString> CAN_NOT_CHANGE_PASSWORD = {
|
|||
};
|
||||
} // namespace
|
||||
|
||||
ProfileForm::ProfileForm(IProfileInfo* profileInfo_, QWidget* parent)
|
||||
ProfileForm::ProfileForm(IProfileInfo* profileInfo_, Settings& settings_,
|
||||
QWidget* parent)
|
||||
: QWidget{parent}
|
||||
, qr{nullptr}
|
||||
, profileInfo{profileInfo_}
|
||||
, settings{settings_}
|
||||
{
|
||||
bodyUI = new Ui::IdentitySettings;
|
||||
bodyUI->setupUi(this);
|
||||
|
@ -131,7 +133,7 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo_, QWidget* parent)
|
|||
profilePicture->installEventFilter(this);
|
||||
profilePicture->setAccessibleName("Profile avatar");
|
||||
profilePicture->setAccessibleDescription("Set a profile avatar shown to all contacts");
|
||||
profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css"));
|
||||
profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css", settings));
|
||||
connect(profilePicture, &MaskablePixmapWidget::clicked, this, &ProfileForm::onAvatarClicked);
|
||||
connect(profilePicture, &MaskablePixmapWidget::customContextMenuRequested,
|
||||
this, &ProfileForm::showProfilePictureContextMenu);
|
||||
|
@ -212,8 +214,8 @@ void ProfileForm::show(ContentLayout* contentLayout)
|
|||
contentLayout->mainContent->layout()->addWidget(this);
|
||||
QWidget::show();
|
||||
prFileLabelUpdate();
|
||||
bool portable = Settings::getInstance().getMakeToxPortable();
|
||||
QString defaultPath = QDir(Settings::getInstance().getPaths().getSettingsDirPath()).path().trimmed();
|
||||
bool portable = settings.getMakeToxPortable();
|
||||
QString defaultPath = QDir(settings.getPaths().getSettingsDirPath()).path().trimmed();
|
||||
QString appPath = QApplication::applicationDirPath();
|
||||
QString dirPath = portable ? appPath : defaultPath;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ class ContentLayout;
|
|||
class CroppingLabel;
|
||||
class IProfileInfo;
|
||||
class MaskablePixmapWidget;
|
||||
class Settings;
|
||||
|
||||
namespace Ui {
|
||||
class IdentitySettings;
|
||||
|
@ -52,7 +53,7 @@ class ProfileForm : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProfileForm(IProfileInfo* profileInfo_, QWidget* parent = nullptr);
|
||||
ProfileForm(IProfileInfo* profileInfo_, Settings&, QWidget* parent = nullptr);
|
||||
~ProfileForm();
|
||||
void show(ContentLayout* contentLayout);
|
||||
bool isShown() const;
|
||||
|
@ -92,4 +93,5 @@ private:
|
|||
QRWidget* qr;
|
||||
ClickableTE* toxId;
|
||||
IProfileInfo* profileInfo;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -23,9 +23,10 @@
|
|||
#include "src/widget/style.h"
|
||||
#include "src/widget/form/loadhistorydialog.h"
|
||||
|
||||
SearchSettingsForm::SearchSettingsForm(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::SearchSettingsForm)
|
||||
SearchSettingsForm::SearchSettingsForm(Settings& settings_, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::SearchSettingsForm)
|
||||
, settings{settings_}
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -99,13 +100,13 @@ ParameterSearch SearchSettingsForm::getParameterSearch()
|
|||
|
||||
void SearchSettingsForm::reloadTheme()
|
||||
{
|
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
|
||||
ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css")));
|
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
|
||||
ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css"), settings));
|
||||
}
|
||||
|
||||
void SearchSettingsForm::updateStartDateLabel()
|
||||
{
|
||||
ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat()));
|
||||
ui->startDateLabel->setText(startDate.toString(settings.getDateFormat()));
|
||||
}
|
||||
|
||||
void SearchSettingsForm::setUpdate(const bool isUpdate_)
|
||||
|
@ -121,7 +122,7 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
|
|||
ui->startDateLabel->setEnabled(true);
|
||||
|
||||
ui->choiceDateButton->setProperty("state", QStringLiteral("green"));
|
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
|
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
|
||||
|
||||
if (startDate.isNull()) {
|
||||
startDate = QDate::currentDate();
|
||||
|
@ -133,7 +134,7 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
|
|||
ui->startDateLabel->setEnabled(false);
|
||||
|
||||
ui->choiceDateButton->setProperty("state", QString());
|
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
|
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
|
||||
}
|
||||
|
||||
setUpdate(true);
|
||||
|
|
|
@ -25,13 +25,14 @@
|
|||
namespace Ui {
|
||||
class SearchSettingsForm;
|
||||
}
|
||||
class Settings;
|
||||
|
||||
class SearchSettingsForm : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SearchSettingsForm(QWidget *parent = nullptr);
|
||||
explicit SearchSettingsForm(Settings&, QWidget *parent = nullptr);
|
||||
~SearchSettingsForm();
|
||||
|
||||
ParameterSearch getParameterSearch();
|
||||
|
@ -41,6 +42,7 @@ private:
|
|||
Ui::SearchSettingsForm *ui;
|
||||
QDate startDate;
|
||||
bool isUpdate{false};
|
||||
Settings& settings;
|
||||
|
||||
void updateStartDateLabel();
|
||||
void setUpdate(const bool isUpdate_);
|
||||
|
|
|
@ -41,30 +41,30 @@
|
|||
* Is also contains "Reset settings" button and "Make portable" checkbox.
|
||||
*/
|
||||
|
||||
AdvancedForm::AdvancedForm()
|
||||
AdvancedForm::AdvancedForm(Settings& settings_)
|
||||
: GenericForm(QPixmap(":/img/settings/general.png"))
|
||||
, bodyUI(new Ui::AdvancedSettings)
|
||||
, settings{settings_}
|
||||
{
|
||||
bodyUI->setupUi(this);
|
||||
|
||||
// block all child signals during initialization
|
||||
const RecursiveSignalBlocker signalBlocker(this);
|
||||
|
||||
Settings& s = Settings::getInstance();
|
||||
bodyUI->cbEnableIPv6->setChecked(s.getEnableIPv6());
|
||||
bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable());
|
||||
bodyUI->proxyAddr->setText(s.getProxyAddr());
|
||||
quint16 port = s.getProxyPort();
|
||||
bodyUI->cbEnableIPv6->setChecked(settings.getEnableIPv6());
|
||||
bodyUI->cbMakeToxPortable->setChecked(settings.getMakeToxPortable());
|
||||
bodyUI->proxyAddr->setText(settings.getProxyAddr());
|
||||
quint16 port = settings.getProxyPort();
|
||||
if (port > 0) {
|
||||
bodyUI->proxyPort->setValue(port);
|
||||
}
|
||||
|
||||
int index = static_cast<int>(s.getProxyType());
|
||||
int index = static_cast<int>(settings.getProxyType());
|
||||
bodyUI->proxyType->setCurrentIndex(index);
|
||||
on_proxyType_currentIndexChanged(index);
|
||||
const bool udpEnabled = !s.getForceTCP() && (s.getProxyType() == Settings::ProxyType::ptNone);
|
||||
const bool udpEnabled = !settings.getForceTCP() && (settings.getProxyType() == Settings::ProxyType::ptNone);
|
||||
bodyUI->cbEnableUDP->setChecked(udpEnabled);
|
||||
bodyUI->cbEnableLanDiscovery->setChecked(s.getEnableLanDiscovery() && udpEnabled);
|
||||
bodyUI->cbEnableLanDiscovery->setChecked(settings.getEnableLanDiscovery() && udpEnabled);
|
||||
bodyUI->cbEnableLanDiscovery->setEnabled(udpEnabled);
|
||||
|
||||
QString warningBody = tr("Unless you %1 know what you are doing, "
|
||||
|
@ -95,7 +95,7 @@ AdvancedForm::~AdvancedForm()
|
|||
|
||||
void AdvancedForm::on_cbMakeToxPortable_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked());
|
||||
settings.setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked());
|
||||
}
|
||||
void AdvancedForm::on_btnExportLog_clicked()
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ void AdvancedForm::on_btnExportLog_clicked()
|
|||
return;
|
||||
}
|
||||
|
||||
QString logFileDir = Settings::getInstance().getPaths().getAppCacheDirPath();
|
||||
QString logFileDir = settings.getPaths().getAppCacheDirPath();
|
||||
QString logfile = logFileDir + "qtox.log";
|
||||
|
||||
QFile file(logfile);
|
||||
|
@ -126,7 +126,7 @@ void AdvancedForm::on_btnExportLog_clicked()
|
|||
|
||||
void AdvancedForm::on_btnCopyDebug_clicked()
|
||||
{
|
||||
QString logFileDir = Settings::getInstance().getPaths().getAppCacheDirPath();
|
||||
QString logFileDir = settings.getPaths().getAppCacheDirPath();
|
||||
QString logfile = logFileDir + "qtox.log";
|
||||
|
||||
QFile file(logfile);
|
||||
|
@ -163,32 +163,32 @@ void AdvancedForm::on_resetButton_clicked()
|
|||
if (!result)
|
||||
return;
|
||||
|
||||
Settings::getInstance().resetToDefault();
|
||||
settings.resetToDefault();
|
||||
GUI::showInfo(titile, "Changes will take effect after restart");
|
||||
}
|
||||
|
||||
void AdvancedForm::on_cbEnableIPv6_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setEnableIPv6(bodyUI->cbEnableIPv6->isChecked());
|
||||
settings.setEnableIPv6(bodyUI->cbEnableIPv6->isChecked());
|
||||
}
|
||||
|
||||
void AdvancedForm::on_cbEnableUDP_stateChanged()
|
||||
{
|
||||
const bool enableUdp = bodyUI->cbEnableUDP->isChecked();
|
||||
Settings::getInstance().setForceTCP(!enableUdp);
|
||||
const bool enableLanDiscovery = Settings::getInstance().getEnableLanDiscovery();
|
||||
settings.setForceTCP(!enableUdp);
|
||||
const bool enableLanDiscovery = settings.getEnableLanDiscovery();
|
||||
bodyUI->cbEnableLanDiscovery->setEnabled(enableUdp);
|
||||
bodyUI->cbEnableLanDiscovery->setChecked(enableUdp && enableLanDiscovery);
|
||||
}
|
||||
|
||||
void AdvancedForm::on_cbEnableLanDiscovery_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setEnableLanDiscovery(bodyUI->cbEnableLanDiscovery->isChecked());
|
||||
settings.setEnableLanDiscovery(bodyUI->cbEnableLanDiscovery->isChecked());
|
||||
}
|
||||
|
||||
void AdvancedForm::on_proxyAddr_editingFinished()
|
||||
{
|
||||
Settings::getInstance().setProxyAddr(bodyUI->proxyAddr->text());
|
||||
settings.setProxyAddr(bodyUI->proxyAddr->text());
|
||||
}
|
||||
|
||||
void AdvancedForm::on_proxyPort_valueChanged(int port)
|
||||
|
@ -197,7 +197,7 @@ void AdvancedForm::on_proxyPort_valueChanged(int port)
|
|||
port = 0;
|
||||
}
|
||||
|
||||
Settings::getInstance().setProxyPort(port);
|
||||
settings.setProxyPort(port);
|
||||
}
|
||||
|
||||
void AdvancedForm::on_proxyType_currentIndexChanged(int index)
|
||||
|
@ -211,7 +211,7 @@ void AdvancedForm::on_proxyType_currentIndexChanged(int index)
|
|||
bodyUI->cbEnableUDP->setEnabled(!proxyEnabled);
|
||||
bodyUI->cbEnableUDP->setChecked(!proxyEnabled);
|
||||
|
||||
Settings::getInstance().setProxyType(proxytype);
|
||||
settings.setProxyType(proxytype);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "genericsettings.h"
|
||||
|
||||
class Core;
|
||||
class Settings;
|
||||
|
||||
namespace Ui {
|
||||
class AdvancedSettings;
|
||||
|
@ -31,7 +32,7 @@ class AdvancedForm : public GenericForm
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AdvancedForm();
|
||||
explicit AdvancedForm(Settings&);
|
||||
~AdvancedForm();
|
||||
QString getFormName() final
|
||||
{
|
||||
|
@ -58,4 +59,5 @@ private:
|
|||
|
||||
private:
|
||||
Ui::AdvancedSettings* bodyUI;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -96,9 +96,10 @@ QStringList locales = {
|
|||
*
|
||||
* This form contains all settings that are not suited to other forms
|
||||
*/
|
||||
GeneralForm::GeneralForm(SettingsWidget* myParent)
|
||||
GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_)
|
||||
: GenericForm(QPixmap(":/img/settings/general.png"))
|
||||
, bodyUI(new Ui::GeneralSettings)
|
||||
, settings{settings_}
|
||||
{
|
||||
parent = myParent;
|
||||
|
||||
|
@ -107,8 +108,6 @@ GeneralForm::GeneralForm(SettingsWidget* myParent)
|
|||
// block all child signals during initialization
|
||||
const RecursiveSignalBlocker signalBlocker(this);
|
||||
|
||||
Settings& s = Settings::getInstance();
|
||||
|
||||
#ifndef UPDATE_CHECK_ENABLED
|
||||
bodyUI->checkUpdates->setVisible(false);
|
||||
#endif
|
||||
|
@ -117,7 +116,7 @@ GeneralForm::GeneralForm(SettingsWidget* myParent)
|
|||
bodyUI->cbSpellChecking->setVisible(false);
|
||||
#endif
|
||||
|
||||
bodyUI->checkUpdates->setChecked(s.getCheckUpdates());
|
||||
bodyUI->checkUpdates->setChecked(settings.getCheckUpdates());
|
||||
|
||||
for (int i = 0; i < locales.size(); ++i) {
|
||||
QString langName;
|
||||
|
@ -136,29 +135,29 @@ GeneralForm::GeneralForm(SettingsWidget* myParent)
|
|||
bodyUI->transComboBox->insertItem(i, langName);
|
||||
}
|
||||
|
||||
bodyUI->transComboBox->setCurrentIndex(locales.indexOf(s.getTranslation()));
|
||||
bodyUI->transComboBox->setCurrentIndex(locales.indexOf(settings.getTranslation()));
|
||||
|
||||
bodyUI->cbAutorun->setChecked(s.getAutorun());
|
||||
bodyUI->cbAutorun->setChecked(settings.getAutorun());
|
||||
|
||||
bodyUI->cbSpellChecking->setChecked(s.getSpellCheckingEnabled());
|
||||
bodyUI->lightTrayIcon->setChecked(s.getLightTrayIcon());
|
||||
bool showSystemTray = s.getShowSystemTray();
|
||||
bodyUI->cbSpellChecking->setChecked(settings.getSpellCheckingEnabled());
|
||||
bodyUI->lightTrayIcon->setChecked(settings.getLightTrayIcon());
|
||||
bool showSystemTray = settings.getShowSystemTray();
|
||||
|
||||
bodyUI->showSystemTray->setChecked(showSystemTray);
|
||||
bodyUI->startInTray->setChecked(s.getAutostartInTray());
|
||||
bodyUI->startInTray->setChecked(settings.getAutostartInTray());
|
||||
bodyUI->startInTray->setEnabled(showSystemTray);
|
||||
bodyUI->minimizeToTray->setChecked(s.getMinimizeToTray());
|
||||
bodyUI->minimizeToTray->setChecked(settings.getMinimizeToTray());
|
||||
bodyUI->minimizeToTray->setEnabled(showSystemTray);
|
||||
bodyUI->closeToTray->setChecked(s.getCloseToTray());
|
||||
bodyUI->closeToTray->setChecked(settings.getCloseToTray());
|
||||
bodyUI->closeToTray->setEnabled(showSystemTray);
|
||||
|
||||
bodyUI->statusChanges->setChecked(s.getStatusChangeNotificationEnabled());
|
||||
bodyUI->groupJoinLeaveMessages->setChecked(s.getShowGroupJoinLeaveMessages());
|
||||
bodyUI->statusChanges->setChecked(settings.getStatusChangeNotificationEnabled());
|
||||
bodyUI->groupJoinLeaveMessages->setChecked(settings.getShowGroupJoinLeaveMessages());
|
||||
|
||||
bodyUI->autoAwaySpinBox->setValue(s.getAutoAwayTime());
|
||||
bodyUI->autoSaveFilesDir->setText(s.getGlobalAutoAcceptDir());
|
||||
bodyUI->maxAutoAcceptSizeMB->setValue(static_cast<double>(s.getMaxAutoAcceptSize()) / 1024 / 1024);
|
||||
bodyUI->autoacceptFiles->setChecked(s.getAutoSaveEnabled());
|
||||
bodyUI->autoAwaySpinBox->setValue(settings.getAutoAwayTime());
|
||||
bodyUI->autoSaveFilesDir->setText(settings.getGlobalAutoAcceptDir());
|
||||
bodyUI->maxAutoAcceptSizeMB->setValue(static_cast<double>(settings.getMaxAutoAcceptSize()) / 1024 / 1024);
|
||||
bodyUI->autoacceptFiles->setChecked(settings.getAutoSaveEnabled());
|
||||
|
||||
|
||||
#ifndef QTOX_PLATFORM_EXT
|
||||
|
@ -179,71 +178,71 @@ GeneralForm::~GeneralForm()
|
|||
void GeneralForm::on_transComboBox_currentIndexChanged(int index)
|
||||
{
|
||||
const QString& locale = locales[index];
|
||||
Settings::getInstance().setTranslation(locale);
|
||||
settings.setTranslation(locale);
|
||||
Translator::translate(locale);
|
||||
}
|
||||
|
||||
void GeneralForm::on_cbAutorun_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setAutorun(bodyUI->cbAutorun->isChecked());
|
||||
settings.setAutorun(bodyUI->cbAutorun->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_cbSpellChecking_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setSpellCheckingEnabled(bodyUI->cbSpellChecking->isChecked());
|
||||
settings.setSpellCheckingEnabled(bodyUI->cbSpellChecking->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_showSystemTray_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setShowSystemTray(bodyUI->showSystemTray->isChecked());
|
||||
Settings::getInstance().saveGlobal();
|
||||
settings.setShowSystemTray(bodyUI->showSystemTray->isChecked());
|
||||
settings.saveGlobal();
|
||||
}
|
||||
|
||||
void GeneralForm::on_startInTray_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked());
|
||||
settings.setAutostartInTray(bodyUI->startInTray->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_closeToTray_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setCloseToTray(bodyUI->closeToTray->isChecked());
|
||||
settings.setCloseToTray(bodyUI->closeToTray->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_lightTrayIcon_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setLightTrayIcon(bodyUI->lightTrayIcon->isChecked());
|
||||
settings.setLightTrayIcon(bodyUI->lightTrayIcon->isChecked());
|
||||
emit updateIcons();
|
||||
}
|
||||
|
||||
void GeneralForm::on_minimizeToTray_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setMinimizeToTray(bodyUI->minimizeToTray->isChecked());
|
||||
settings.setMinimizeToTray(bodyUI->minimizeToTray->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_statusChanges_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChanges->isChecked());
|
||||
settings.setStatusChangeNotificationEnabled(bodyUI->statusChanges->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_groupJoinLeaveMessages_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setShowGroupJoinLeaveMessages(bodyUI->groupJoinLeaveMessages->isChecked());
|
||||
settings.setShowGroupJoinLeaveMessages(bodyUI->groupJoinLeaveMessages->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_autoAwaySpinBox_editingFinished()
|
||||
{
|
||||
int minutes = bodyUI->autoAwaySpinBox->value();
|
||||
Settings::getInstance().setAutoAwayTime(minutes);
|
||||
settings.setAutoAwayTime(minutes);
|
||||
}
|
||||
|
||||
void GeneralForm::on_autoacceptFiles_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setAutoSaveEnabled(bodyUI->autoacceptFiles->isChecked());
|
||||
settings.setAutoSaveEnabled(bodyUI->autoacceptFiles->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::on_autoSaveFilesDir_clicked()
|
||||
{
|
||||
QString previousDir = Settings::getInstance().getGlobalAutoAcceptDir();
|
||||
QString previousDir = settings.getGlobalAutoAcceptDir();
|
||||
QString directory =
|
||||
QFileDialog::getExistingDirectory(Q_NULLPTR,
|
||||
tr("Choose an auto accept directory", "popup title"),
|
||||
|
@ -251,7 +250,7 @@ void GeneralForm::on_autoSaveFilesDir_clicked()
|
|||
if (directory.isEmpty()) // cancel was pressed
|
||||
directory = previousDir;
|
||||
|
||||
Settings::getInstance().setGlobalAutoAcceptDir(directory);
|
||||
settings.setGlobalAutoAcceptDir(directory);
|
||||
bodyUI->autoSaveFilesDir->setText(directory);
|
||||
}
|
||||
|
||||
|
@ -260,12 +259,12 @@ void GeneralForm::on_maxAutoAcceptSizeMB_editingFinished()
|
|||
auto newMaxSizeMB = bodyUI->maxAutoAcceptSizeMB->value();
|
||||
auto newMaxSizeB = std::lround(newMaxSizeMB * 1024 * 1024);
|
||||
|
||||
Settings::getInstance().setMaxAutoAcceptSize(newMaxSizeB);
|
||||
settings.setMaxAutoAcceptSize(newMaxSizeB);
|
||||
}
|
||||
|
||||
void GeneralForm::on_checkUpdates_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setCheckUpdates(bodyUI->checkUpdates->isChecked());
|
||||
settings.setCheckUpdates(bodyUI->checkUpdates->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,12 +26,13 @@ class GeneralSettings;
|
|||
}
|
||||
|
||||
class SettingsWidget;
|
||||
class Settings;
|
||||
|
||||
class GeneralForm : public GenericForm
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GeneralForm(SettingsWidget* parent);
|
||||
explicit GeneralForm(SettingsWidget* parent, Settings&);
|
||||
~GeneralForm();
|
||||
QString getFormName() final
|
||||
{
|
||||
|
@ -63,4 +64,5 @@ private:
|
|||
private:
|
||||
Ui::GeneralSettings* bodyUI;
|
||||
SettingsWidget* parent;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -39,10 +39,11 @@
|
|||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
PrivacyForm::PrivacyForm(Core* _core)
|
||||
PrivacyForm::PrivacyForm(Core* core_, Settings& settings_)
|
||||
: GenericForm(QPixmap(":/img/settings/privacy.png"))
|
||||
, bodyUI(new Ui::PrivacySettings)
|
||||
, core{_core}
|
||||
, core{core_}
|
||||
, settings{settings_}
|
||||
{
|
||||
bodyUI->setupUi(this);
|
||||
|
||||
|
@ -61,7 +62,7 @@ PrivacyForm::~PrivacyForm()
|
|||
|
||||
void PrivacyForm::on_cbKeepHistory_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setEnableLogging(bodyUI->cbKeepHistory->isChecked());
|
||||
settings.setEnableLogging(bodyUI->cbKeepHistory->isChecked());
|
||||
if (!bodyUI->cbKeepHistory->isChecked()) {
|
||||
emit clearAllReceipts();
|
||||
QMessageBox::StandardButton dialogDelHistory;
|
||||
|
@ -77,7 +78,7 @@ void PrivacyForm::on_cbKeepHistory_stateChanged()
|
|||
|
||||
void PrivacyForm::on_cbTypingNotification_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setTypingNotification(bodyUI->cbTypingNotification->isChecked());
|
||||
settings.setTypingNotification(bodyUI->cbTypingNotification->isChecked());
|
||||
}
|
||||
|
||||
void PrivacyForm::on_nospamLineEdit_editingFinished()
|
||||
|
@ -93,10 +94,10 @@ void PrivacyForm::on_nospamLineEdit_editingFinished()
|
|||
|
||||
void PrivacyForm::showEvent(QShowEvent*)
|
||||
{
|
||||
const Settings& s = Settings::getInstance();
|
||||
const Settings& s = settings;
|
||||
bodyUI->nospamLineEdit->setText(core->getSelfId().getNoSpamString());
|
||||
bodyUI->cbTypingNotification->setChecked(s.getTypingNotification());
|
||||
bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging());
|
||||
bodyUI->cbKeepHistory->setChecked(settings.getEnableLogging());
|
||||
bodyUI->blackListTextEdit->setText(s.getBlackList().join('\n'));
|
||||
}
|
||||
|
||||
|
@ -125,7 +126,7 @@ void PrivacyForm::on_nospamLineEdit_textChanged()
|
|||
void PrivacyForm::on_blackListTextEdit_textChanged()
|
||||
{
|
||||
const QStringList strlist = bodyUI->blackListTextEdit->toPlainText().split('\n');
|
||||
Settings::getInstance().setBlackList(strlist);
|
||||
settings.setBlackList(strlist);
|
||||
}
|
||||
|
||||
void PrivacyForm::retranslateUi()
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "genericsettings.h"
|
||||
|
||||
class Core;
|
||||
class Settings;
|
||||
|
||||
namespace Ui {
|
||||
class PrivacySettings;
|
||||
|
@ -31,7 +32,7 @@ class PrivacyForm : public GenericForm
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PrivacyForm(Core* _core);
|
||||
PrivacyForm(Core* core_, Settings&);
|
||||
~PrivacyForm();
|
||||
QString getFormName() final
|
||||
{
|
||||
|
@ -56,4 +57,5 @@ private:
|
|||
private:
|
||||
Ui::PrivacySettings* bodyUI;
|
||||
Core* core;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -54,9 +54,11 @@
|
|||
*
|
||||
* Restores all controls from the settings.
|
||||
*/
|
||||
UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, SettingsWidget* myParent)
|
||||
UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, Settings& settings_,
|
||||
SettingsWidget* myParent)
|
||||
: GenericForm(QPixmap(":/img/settings/general.png"))
|
||||
, smileyPack{smileyPack_}
|
||||
, settings{settings_}
|
||||
{
|
||||
parent = myParent;
|
||||
|
||||
|
@ -66,46 +68,45 @@ UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, SettingsWidget* my
|
|||
// block all child signals during initialization
|
||||
const RecursiveSignalBlocker signalBlocker(this);
|
||||
|
||||
Settings& s = Settings::getInstance();
|
||||
const QFont chatBaseFont = s.getChatMessageFont();
|
||||
const QFont chatBaseFont = settings.getChatMessageFont();
|
||||
bodyUI->txtChatFontSize->setValue(QFontInfo(chatBaseFont).pixelSize());
|
||||
bodyUI->txtChatFont->setCurrentFont(chatBaseFont);
|
||||
int index = static_cast<int>(s.getStylePreference());
|
||||
int index = static_cast<int>(settings.getStylePreference());
|
||||
bodyUI->textStyleComboBox->setCurrentIndex(index);
|
||||
bodyUI->useNameColors->setChecked(s.getEnableGroupChatsColor());
|
||||
bodyUI->useNameColors->setChecked(settings.getEnableGroupChatsColor());
|
||||
|
||||
bodyUI->notify->setChecked(s.getNotify());
|
||||
bodyUI->notify->setChecked(settings.getNotify());
|
||||
// Note: UI is boolean inversed from settings to maintain setting file backwards compatibility
|
||||
bodyUI->groupOnlyNotfiyWhenMentioned->setChecked(!s.getGroupAlwaysNotify());
|
||||
bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(s.getNotify());
|
||||
bodyUI->notifySound->setChecked(s.getNotifySound());
|
||||
bodyUI->notifyHide->setChecked(s.getNotifyHide());
|
||||
bodyUI->notifySound->setEnabled(s.getNotify());
|
||||
bodyUI->busySound->setChecked(s.getBusySound());
|
||||
bodyUI->busySound->setEnabled(s.getNotifySound() && s.getNotify());
|
||||
bodyUI->groupOnlyNotfiyWhenMentioned->setChecked(!settings.getGroupAlwaysNotify());
|
||||
bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(settings.getNotify());
|
||||
bodyUI->notifySound->setChecked(settings.getNotifySound());
|
||||
bodyUI->notifyHide->setChecked(settings.getNotifyHide());
|
||||
bodyUI->notifySound->setEnabled(settings.getNotify());
|
||||
bodyUI->busySound->setChecked(settings.getBusySound());
|
||||
bodyUI->busySound->setEnabled(settings.getNotifySound() && settings.getNotify());
|
||||
#if DESKTOP_NOTIFICATIONS
|
||||
bodyUI->desktopNotify->setChecked(s.getDesktopNotify());
|
||||
bodyUI->desktopNotify->setEnabled(s.getNotify());
|
||||
bodyUI->desktopNotify->setChecked(settings.getDesktopNotify());
|
||||
bodyUI->desktopNotify->setEnabled(settings.getNotify());
|
||||
#else
|
||||
bodyUI->desktopNotify->hide();
|
||||
#endif
|
||||
|
||||
bodyUI->showWindow->setChecked(s.getShowWindow());
|
||||
bodyUI->showWindow->setChecked(settings.getShowWindow());
|
||||
|
||||
bodyUI->cbGroupchatPosition->setChecked(s.getGroupchatPosition());
|
||||
bodyUI->cbCompactLayout->setChecked(s.getCompactLayout());
|
||||
bodyUI->cbSeparateWindow->setChecked(s.getSeparateWindow());
|
||||
bodyUI->cbDontGroupWindows->setChecked(s.getDontGroupWindows());
|
||||
bodyUI->cbDontGroupWindows->setEnabled(s.getSeparateWindow());
|
||||
bodyUI->cbShowIdenticons->setChecked(s.getShowIdenticons());
|
||||
bodyUI->cbGroupchatPosition->setChecked(settings.getGroupchatPosition());
|
||||
bodyUI->cbCompactLayout->setChecked(settings.getCompactLayout());
|
||||
bodyUI->cbSeparateWindow->setChecked(settings.getSeparateWindow());
|
||||
bodyUI->cbDontGroupWindows->setChecked(settings.getDontGroupWindows());
|
||||
bodyUI->cbDontGroupWindows->setEnabled(settings.getSeparateWindow());
|
||||
bodyUI->cbShowIdenticons->setChecked(settings.getShowIdenticons());
|
||||
|
||||
bodyUI->useEmoticons->setChecked(s.getUseEmoticons());
|
||||
bodyUI->useEmoticons->setChecked(settings.getUseEmoticons());
|
||||
for (auto entry : SmileyPack::listSmileyPacks())
|
||||
bodyUI->smileyPackBrowser->addItem(entry.first, entry.second);
|
||||
|
||||
smileLabels = {bodyUI->smile1, bodyUI->smile2, bodyUI->smile3, bodyUI->smile4, bodyUI->smile5};
|
||||
|
||||
int currentPack = bodyUI->smileyPackBrowser->findData(s.getSmileyPack());
|
||||
int currentPack = bodyUI->smileyPackBrowser->findData(settings.getSmileyPack());
|
||||
bodyUI->smileyPackBrowser->setCurrentIndex(currentPack);
|
||||
reloadSmileys();
|
||||
bodyUI->smileyPackBrowser->setEnabled(bodyUI->useEmoticons->isChecked());
|
||||
|
@ -114,8 +115,8 @@ UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, SettingsWidget* my
|
|||
bodyUI->styleBrowser->addItems(QStyleFactory::keys());
|
||||
|
||||
QString style;
|
||||
if (QStyleFactory::keys().contains(s.getStyle()))
|
||||
style = s.getStyle();
|
||||
if (QStyleFactory::keys().contains(settings.getStyle()))
|
||||
style = settings.getStyle();
|
||||
else
|
||||
style = tr("None");
|
||||
|
||||
|
@ -124,8 +125,8 @@ UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, SettingsWidget* my
|
|||
for (QString color : Style::getThemeColorNames())
|
||||
bodyUI->themeColorCBox->addItem(color);
|
||||
|
||||
bodyUI->themeColorCBox->setCurrentIndex(s.getThemeColor());
|
||||
bodyUI->emoticonSize->setValue(s.getEmojiFontPointSize());
|
||||
bodyUI->themeColorCBox->setCurrentIndex(settings.getThemeColor());
|
||||
bodyUI->emoticonSize->setValue(settings.getEmojiFontPointSize());
|
||||
|
||||
QLocale ql;
|
||||
QStringList timeFormats;
|
||||
|
@ -138,7 +139,7 @@ UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, SettingsWidget* my
|
|||
|
||||
QRegularExpression re(QString("^[^\\n]{0,%0}$").arg(MAX_FORMAT_LENGTH));
|
||||
QRegularExpressionValidator* validator = new QRegularExpressionValidator(re, this);
|
||||
QString timeFormat = s.getTimestampFormat();
|
||||
QString timeFormat = settings.getTimestampFormat();
|
||||
|
||||
if (!re.match(timeFormat).hasMatch())
|
||||
timeFormat = timeFormats[0];
|
||||
|
@ -159,7 +160,7 @@ UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, SettingsWidget* my
|
|||
dateFormats.removeDuplicates();
|
||||
bodyUI->dateFormats->addItems(dateFormats);
|
||||
|
||||
QString dateFormat = s.getDateFormat();
|
||||
QString dateFormat = settings.getDateFormat();
|
||||
if (!re.match(dateFormat).hasMatch())
|
||||
dateFormat = dateFormats[0];
|
||||
|
||||
|
@ -180,9 +181,9 @@ UserInterfaceForm::~UserInterfaceForm()
|
|||
void UserInterfaceForm::on_styleBrowser_currentIndexChanged(QString style)
|
||||
{
|
||||
if (bodyUI->styleBrowser->currentIndex() == 0)
|
||||
Settings::getInstance().setStyle("None");
|
||||
settings.setStyle("None");
|
||||
else
|
||||
Settings::getInstance().setStyle(style);
|
||||
settings.setStyle(style);
|
||||
|
||||
setStyle(QStyleFactory::create(style));
|
||||
parent->setBodyHeadStyle(style);
|
||||
|
@ -190,7 +191,7 @@ void UserInterfaceForm::on_styleBrowser_currentIndexChanged(QString style)
|
|||
|
||||
void UserInterfaceForm::on_emoticonSize_editingFinished()
|
||||
{
|
||||
Settings::getInstance().setEmojiFontPointSize(bodyUI->emoticonSize->value());
|
||||
settings.setEmojiFontPointSize(bodyUI->emoticonSize->value());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_timestamp_editTextChanged(const QString& format)
|
||||
|
@ -198,8 +199,8 @@ void UserInterfaceForm::on_timestamp_editTextChanged(const QString& format)
|
|||
QString timeExample = QTime::currentTime().toString(format);
|
||||
bodyUI->timeExample->setText(timeExample);
|
||||
|
||||
Settings::getInstance().setTimestampFormat(format);
|
||||
QString locale = Settings::getInstance().getTranslation();
|
||||
settings.setTimestampFormat(format);
|
||||
QString locale = settings.getTranslation();
|
||||
Translator::translate(locale);
|
||||
}
|
||||
|
||||
|
@ -208,14 +209,14 @@ void UserInterfaceForm::on_dateFormats_editTextChanged(const QString& format)
|
|||
QString dateExample = QDate::currentDate().toString(format);
|
||||
bodyUI->dateExample->setText(dateExample);
|
||||
|
||||
Settings::getInstance().setDateFormat(format);
|
||||
QString locale = Settings::getInstance().getTranslation();
|
||||
settings.setDateFormat(format);
|
||||
QString locale = settings.getTranslation();
|
||||
Translator::translate(locale);
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_useEmoticons_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setUseEmoticons(bodyUI->useEmoticons->isChecked());
|
||||
settings.setUseEmoticons(bodyUI->useEmoticons->isChecked());
|
||||
bodyUI->smileyPackBrowser->setEnabled(bodyUI->useEmoticons->isChecked());
|
||||
}
|
||||
|
||||
|
@ -223,13 +224,13 @@ void UserInterfaceForm::on_textStyleComboBox_currentTextChanged()
|
|||
{
|
||||
Settings::StyleType styleType =
|
||||
static_cast<Settings::StyleType>(bodyUI->textStyleComboBox->currentIndex());
|
||||
Settings::getInstance().setStylePreference(styleType);
|
||||
settings.setStylePreference(styleType);
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_smileyPackBrowser_currentIndexChanged(int index)
|
||||
{
|
||||
QString filename = bodyUI->smileyPackBrowser->itemData(index).toString();
|
||||
Settings::getInstance().setSmileyPack(filename);
|
||||
settings.setSmileyPack(filename);
|
||||
reloadSmileys();
|
||||
}
|
||||
|
||||
|
@ -273,7 +274,7 @@ void UserInterfaceForm::reloadSmileys()
|
|||
void UserInterfaceForm::on_notify_stateChanged()
|
||||
{
|
||||
const bool notify = bodyUI->notify->isChecked();
|
||||
Settings::getInstance().setNotify(notify);
|
||||
settings.setNotify(notify);
|
||||
bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(notify);
|
||||
bodyUI->notifySound->setEnabled(notify);
|
||||
bodyUI->busySound->setEnabled(notify && bodyUI->notifySound->isChecked());
|
||||
|
@ -283,64 +284,64 @@ void UserInterfaceForm::on_notify_stateChanged()
|
|||
void UserInterfaceForm::on_notifySound_stateChanged()
|
||||
{
|
||||
const bool notify = bodyUI->notifySound->isChecked();
|
||||
Settings::getInstance().setNotifySound(notify);
|
||||
settings.setNotifySound(notify);
|
||||
bodyUI->busySound->setEnabled(notify);
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_desktopNotify_stateChanged()
|
||||
{
|
||||
const bool notify = bodyUI->desktopNotify->isChecked();
|
||||
Settings::getInstance().setDesktopNotify(notify);
|
||||
settings.setDesktopNotify(notify);
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_busySound_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setBusySound(bodyUI->busySound->isChecked());
|
||||
settings.setBusySound(bodyUI->busySound->isChecked());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_showWindow_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setShowWindow(bodyUI->showWindow->isChecked());
|
||||
settings.setShowWindow(bodyUI->showWindow->isChecked());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_groupOnlyNotfiyWhenMentioned_stateChanged()
|
||||
{
|
||||
// Note: UI is boolean inversed from settings to maintain setting file backwards compatibility
|
||||
Settings::getInstance().setGroupAlwaysNotify(!bodyUI->groupOnlyNotfiyWhenMentioned->isChecked());
|
||||
settings.setGroupAlwaysNotify(!bodyUI->groupOnlyNotfiyWhenMentioned->isChecked());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_cbCompactLayout_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setCompactLayout(bodyUI->cbCompactLayout->isChecked());
|
||||
settings.setCompactLayout(bodyUI->cbCompactLayout->isChecked());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_cbSeparateWindow_stateChanged()
|
||||
{
|
||||
bool checked = bodyUI->cbSeparateWindow->isChecked();
|
||||
bodyUI->cbDontGroupWindows->setEnabled(checked);
|
||||
Settings::getInstance().setSeparateWindow(checked);
|
||||
settings.setSeparateWindow(checked);
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_cbDontGroupWindows_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setDontGroupWindows(bodyUI->cbDontGroupWindows->isChecked());
|
||||
settings.setDontGroupWindows(bodyUI->cbDontGroupWindows->isChecked());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_cbGroupchatPosition_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setGroupchatPosition(bodyUI->cbGroupchatPosition->isChecked());
|
||||
settings.setGroupchatPosition(bodyUI->cbGroupchatPosition->isChecked());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_cbShowIdenticons_stateChanged()
|
||||
{
|
||||
Settings::getInstance().setShowIdenticons(bodyUI->cbShowIdenticons->isChecked());
|
||||
settings.setShowIdenticons(bodyUI->cbShowIdenticons->isChecked());
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_themeColorCBox_currentIndexChanged(int)
|
||||
{
|
||||
int index = bodyUI->themeColorCBox->currentIndex();
|
||||
Settings::getInstance().setThemeColor(index);
|
||||
Style::setThemeColor(index);
|
||||
settings.setThemeColor(index);
|
||||
Style::setThemeColor(settings, index);
|
||||
Style::applyTheme();
|
||||
}
|
||||
|
||||
|
@ -356,7 +357,7 @@ void UserInterfaceForm::retranslateUi()
|
|||
|
||||
// Restore text style index once translation is complete
|
||||
bodyUI->textStyleComboBox->setCurrentIndex(
|
||||
static_cast<int>(Settings::getInstance().getStylePreference()));
|
||||
static_cast<int>(settings.getStylePreference()));
|
||||
|
||||
QStringList colorThemes(Style::getThemeColorNames());
|
||||
for (int i = 0; i < colorThemes.size(); ++i) {
|
||||
|
@ -374,12 +375,12 @@ void UserInterfaceForm::on_txtChatFont_currentFontChanged(const QFont& f)
|
|||
if (QFontInfo(tmpFont).pixelSize() != px)
|
||||
tmpFont.setPixelSize(px);
|
||||
|
||||
Settings::getInstance().setChatMessageFont(tmpFont);
|
||||
settings.setChatMessageFont(tmpFont);
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_txtChatFontSize_valueChanged(int px)
|
||||
{
|
||||
Settings& s = Settings::getInstance();
|
||||
Settings& s = settings;
|
||||
QFont tmpFont = s.getChatMessageFont();
|
||||
const int fontSize = QFontInfo(tmpFont).pixelSize();
|
||||
|
||||
|
@ -391,10 +392,10 @@ void UserInterfaceForm::on_txtChatFontSize_valueChanged(int px)
|
|||
|
||||
void UserInterfaceForm::on_useNameColors_stateChanged(int value)
|
||||
{
|
||||
Settings::getInstance().setEnableGroupChatsColor(value);
|
||||
settings.setEnableGroupChatsColor(value);
|
||||
}
|
||||
|
||||
void UserInterfaceForm::on_notifyHide_stateChanged(int value)
|
||||
{
|
||||
Settings::getInstance().setNotifyHide(value);
|
||||
settings.setNotifyHide(value);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
namespace Ui {
|
||||
class UserInterfaceSettings;
|
||||
}
|
||||
class Settings;
|
||||
|
||||
class SmileyPack;
|
||||
|
||||
|
@ -34,7 +35,7 @@ class UserInterfaceForm : public GenericForm
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UserInterfaceForm(SmileyPack&, SettingsWidget* myParent);
|
||||
UserInterfaceForm(SmileyPack&, Settings&, SettingsWidget* myParent);
|
||||
~UserInterfaceForm();
|
||||
QString getFormName() final
|
||||
{
|
||||
|
@ -77,4 +78,5 @@ private:
|
|||
Ui::UserInterfaceSettings* bodyUI;
|
||||
const int MAX_FORMAT_LENGTH = 128;
|
||||
SmileyPack& smileyPack;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -42,12 +42,13 @@
|
|||
#include <memory>
|
||||
|
||||
SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio,
|
||||
Core* core, SmileyPack& smileyPack, CameraSource& cameraSource, Widget* parent)
|
||||
Core* core, SmileyPack& smileyPack, CameraSource& cameraSource,
|
||||
Settings& settings, Widget* parent)
|
||||
: QWidget(parent, Qt::Window)
|
||||
{
|
||||
CoreAV* coreAV = core->getAv();
|
||||
IAudioSettings* audioSettings = &Settings::getInstance();
|
||||
IVideoSettings* videoSettings = &Settings::getInstance();
|
||||
IAudioSettings* audioSettings = &settings;
|
||||
IVideoSettings* videoSettings = &settings;
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
|
@ -57,16 +58,16 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio,
|
|||
settingsWidgets->setTabPosition(QTabWidget::North);
|
||||
bodyLayout->addWidget(settingsWidgets.get());
|
||||
|
||||
std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this));
|
||||
std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this, settings));
|
||||
connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons);
|
||||
|
||||
std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(smileyPack, this));
|
||||
std::unique_ptr<PrivacyForm> pfrm(new PrivacyForm(core));
|
||||
std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(smileyPack, settings, this));
|
||||
std::unique_ptr<PrivacyForm> pfrm(new PrivacyForm(core, settings));
|
||||
connect(pfrm.get(), &PrivacyForm::clearAllReceipts, parent, &Widget::clearAllReceipts);
|
||||
|
||||
AVForm* rawAvfrm = new AVForm(audio, coreAV, cameraSource, audioSettings, videoSettings);
|
||||
std::unique_ptr<AVForm> avfrm(rawAvfrm);
|
||||
std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm());
|
||||
std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm(settings));
|
||||
std::unique_ptr<AboutForm> abtfrm(new AboutForm(updateCheck));
|
||||
|
||||
#if UPDATE_CHECK_ENABLED
|
||||
|
|
|
@ -40,12 +40,14 @@ class UpdateCheck;
|
|||
class Widget;
|
||||
class SmileyPack;
|
||||
class CameraSource;
|
||||
class Settings;
|
||||
|
||||
class SettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, Core *core, SmileyPack&, CameraSource&, Widget* parent = nullptr);
|
||||
SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, Core *core,
|
||||
SmileyPack&, CameraSource&, Settings&, Widget* parent = nullptr);
|
||||
~SettingsWidget();
|
||||
|
||||
bool isShown() const;
|
||||
|
|
|
@ -85,9 +85,9 @@ Time getTimeBucket(const QDateTime& date)
|
|||
return Time::LongAgo;
|
||||
}
|
||||
|
||||
QDateTime getActiveTimeFriend(const Friend* contact)
|
||||
QDateTime getActiveTimeFriend(const Friend* contact, Settings& settings)
|
||||
{
|
||||
return Settings::getInstance().getFriendActivity(contact->getPublicKey());
|
||||
return settings.getFriendActivity(contact->getPublicKey());
|
||||
}
|
||||
|
||||
qint64 timeUntilTomorrow()
|
||||
|
@ -99,9 +99,11 @@ qint64 timeUntilTomorrow()
|
|||
}
|
||||
} // namespace
|
||||
|
||||
FriendListWidget::FriendListWidget(const Core &_core, Widget* parent, bool groupsOnTop)
|
||||
FriendListWidget::FriendListWidget(const Core &core_, Widget* parent,
|
||||
Settings& settings_, bool groupsOnTop)
|
||||
: QWidget(parent)
|
||||
, core{_core}
|
||||
, core{core_}
|
||||
, settings{settings_}
|
||||
{
|
||||
int countContacts = core.getFriendList().size();
|
||||
manager = new FriendListManager(countContacts, this);
|
||||
|
@ -114,7 +116,7 @@ FriendListWidget::FriendListWidget(const Core &_core, Widget* parent, bool group
|
|||
listLayout->setSpacing(0);
|
||||
listLayout->setMargin(0);
|
||||
|
||||
mode = Settings::getInstance().getFriendSortingMode();
|
||||
mode = settings.getFriendSortingMode();
|
||||
|
||||
dayTimer = new QTimer(this);
|
||||
dayTimer->setTimerType(Qt::VeryCoarseTimer);
|
||||
|
@ -126,7 +128,7 @@ FriendListWidget::FriendListWidget(const Core &_core, Widget* parent, bool group
|
|||
|
||||
FriendListWidget::~FriendListWidget()
|
||||
{
|
||||
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i) {
|
||||
for (int i = 0; i < settings.getCircleCount(); ++i) {
|
||||
CircleWidget* circle = CircleWidget::getFromID(i);
|
||||
delete circle;
|
||||
}
|
||||
|
@ -138,7 +140,7 @@ void FriendListWidget::setMode(SortingMode mode_)
|
|||
return;
|
||||
|
||||
mode = mode_;
|
||||
Settings::getInstance().setFriendSortingMode(mode);
|
||||
settings.setFriendSortingMode(mode);
|
||||
|
||||
manager->setSortRequired();
|
||||
}
|
||||
|
@ -153,7 +155,7 @@ void FriendListWidget::sortByMode()
|
|||
|
||||
cleanMainLayout();
|
||||
|
||||
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i) {
|
||||
for (int i = 0; i < settings.getCircleCount(); ++i) {
|
||||
addCircleWidget(i);
|
||||
}
|
||||
|
||||
|
@ -188,7 +190,7 @@ void FriendListWidget::sortByMode()
|
|||
if (!manager->needHideCircles()) {
|
||||
//Sorts circles alphabetically and adds them to the layout
|
||||
QVector<CircleWidget*> circles;
|
||||
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i) {
|
||||
for (int i = 0; i < settings.getCircleCount(); ++i) {
|
||||
circles.push_back(CircleWidget::getFromID(i));
|
||||
}
|
||||
|
||||
|
@ -215,7 +217,7 @@ void FriendListWidget::sortByMode()
|
|||
}
|
||||
cleanMainLayout();
|
||||
|
||||
QLocale ql(Settings::getInstance().getTranslation());
|
||||
QLocale ql(settings.getTranslation());
|
||||
QDate today = QDate::currentDate();
|
||||
#define COMMENT "Category for sorting friends by activity"
|
||||
// clang-format off
|
||||
|
@ -242,9 +244,9 @@ void FriendListWidget::sortByMode()
|
|||
}
|
||||
|
||||
activityLayout = new QVBoxLayout();
|
||||
bool compact = Settings::getInstance().getCompactLayout();
|
||||
bool compact = settings.getCompactLayout();
|
||||
for (Time t : names.keys()) {
|
||||
CategoryWidget* category = new CategoryWidget(compact, this);
|
||||
CategoryWidget* category = new CategoryWidget(compact, settings, this);
|
||||
category->setName(names[t]);
|
||||
activityLayout->addWidget(category);
|
||||
}
|
||||
|
@ -336,7 +338,7 @@ FriendListWidget::getItemsFromCircle(CircleWidget *circle) const
|
|||
|
||||
CategoryWidget* FriendListWidget::getTimeCategoryWidget(const Friend* frd) const
|
||||
{
|
||||
const auto activityTime = getActiveTimeFriend(frd);
|
||||
const auto activityTime = getActiveTimeFriend(frd, settings);
|
||||
int timeIndex = static_cast<int>(getTimeBucket(activityTime));
|
||||
QWidget* widget = activityLayout->itemAt(timeIndex)->widget();
|
||||
return qobject_cast<CategoryWidget*>(widget);
|
||||
|
@ -371,7 +373,7 @@ void FriendListWidget::removeGroupWidget(GroupWidget* w)
|
|||
void FriendListWidget::removeFriendWidget(FriendWidget* w)
|
||||
{
|
||||
const Friend* contact = w->getFriend();
|
||||
int id = Settings::getInstance().getFriendCircleID(contact->getPublicKey());
|
||||
int id = settings.getFriendCircleID(contact->getPublicKey());
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(id);
|
||||
if (circleWidget != nullptr) {
|
||||
circleWidget->removeFriendWidget(w, contact->getStatus());
|
||||
|
@ -454,7 +456,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
return;
|
||||
}
|
||||
|
||||
const auto activityTime = getActiveTimeFriend(friendWidget->getFriend());
|
||||
const auto activityTime = getActiveTimeFriend(friendWidget->getFriend(), settings);
|
||||
index = static_cast<int>(getTimeBucket(activityTime));
|
||||
QWidget* widget_ = activityLayout->itemAt(index)->widget();
|
||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget_);
|
||||
|
@ -541,7 +543,7 @@ void FriendListWidget::dropEvent(QDropEvent* event)
|
|||
return;
|
||||
|
||||
// Save CircleWidget before changing the Id
|
||||
int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
|
||||
int circleId = settings.getFriendCircleID(f->getPublicKey());
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||
|
||||
moveWidget(widget, f->getStatus(), true);
|
||||
|
@ -568,12 +570,12 @@ void FriendListWidget::moveWidget(FriendWidget* widget, Status::Status s, bool a
|
|||
{
|
||||
if (mode == SortingMode::Name) {
|
||||
const Friend* f = widget->getFriend();
|
||||
int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
|
||||
int circleId = settings.getFriendCircleID(f->getPublicKey());
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||
|
||||
if (circleWidget == nullptr || add) {
|
||||
if (circleId != -1) {
|
||||
Settings::getInstance().setFriendCircleID(f->getPublicKey(), -1);
|
||||
settings.setFriendCircleID(f->getPublicKey(), -1);
|
||||
manager->setSortRequired();
|
||||
} else {
|
||||
itemsChanged();
|
||||
|
@ -607,13 +609,13 @@ void FriendListWidget::updateActivityTime(const QDateTime& time)
|
|||
CircleWidget* FriendListWidget::createCircleWidget(int id)
|
||||
{
|
||||
if (id == -1)
|
||||
id = Settings::getInstance().addCircle();
|
||||
id = settings.addCircle();
|
||||
|
||||
if (CircleWidget::getFromID(id) != nullptr) {
|
||||
return CircleWidget::getFromID(id);
|
||||
}
|
||||
|
||||
CircleWidget* circleWidget = new CircleWidget(core, this, id);
|
||||
CircleWidget* circleWidget = new CircleWidget(core, this, id, settings);
|
||||
emit connectCircleWidget(*circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
|
|
|
@ -38,13 +38,14 @@ class GenericChatroomWidget;
|
|||
class CategoryWidget;
|
||||
class Friend;
|
||||
class IFriendListItem;
|
||||
class Settings;
|
||||
|
||||
class FriendListWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using SortingMode = Settings::FriendListSortingMode;
|
||||
explicit FriendListWidget(const Core& _core, Widget* parent, bool groupsOnTop = true);
|
||||
FriendListWidget(const Core&, Widget* parent, Settings&, bool groupsOnTop = true);
|
||||
~FriendListWidget();
|
||||
void setMode(SortingMode mode);
|
||||
SortingMode getMode() const;
|
||||
|
@ -97,4 +98,5 @@ private:
|
|||
FriendListManager* manager;
|
||||
|
||||
const Core& core;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -56,10 +56,11 @@
|
|||
* For example, used on friend list.
|
||||
* When you click should open the chat with friend. Widget has a context menu.
|
||||
*/
|
||||
FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compact_)
|
||||
: GenericChatroomWidget(compact_)
|
||||
FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compact_, Settings& settings_)
|
||||
: GenericChatroomWidget(compact_, settings_)
|
||||
, chatroom{chatroom_}
|
||||
, isDefaultAvatar{true}
|
||||
, settings{settings_}
|
||||
{
|
||||
avatar->setPixmap(QPixmap(":/img/contact.svg"));
|
||||
statusPic.setPixmap(QPixmap(Status::getIconPath(Status::Status::Offline)));
|
||||
|
@ -188,10 +189,11 @@ void FriendWidget::removeChatWindow()
|
|||
|
||||
namespace {
|
||||
|
||||
std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(const Friend* frnd, FriendWidget* fw)
|
||||
std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(const Friend* frnd,
|
||||
FriendWidget* fw, Settings& settings)
|
||||
{
|
||||
const auto pk = frnd->getPublicKey();
|
||||
const auto circleId = Settings::getInstance().getFriendCircleID(pk);
|
||||
const auto circleId = settings.getFriendCircleID(pk);
|
||||
auto circleWidget = CircleWidget::getFromID(circleId);
|
||||
auto w = circleWidget ? static_cast<QWidget*>(circleWidget) : static_cast<QWidget*>(fw);
|
||||
auto friendList = qobject_cast<FriendListWidget*>(w->parentWidget());
|
||||
|
@ -205,7 +207,7 @@ void FriendWidget::moveToNewCircle()
|
|||
const auto frnd = chatroom->getFriend();
|
||||
CircleWidget* circleWidget;
|
||||
FriendListWidget* friendList;
|
||||
std::tie(circleWidget, friendList) = getCircleAndFriendList(frnd, this);
|
||||
std::tie(circleWidget, friendList) = getCircleAndFriendList(frnd, this, settings);
|
||||
|
||||
if (circleWidget != nullptr) {
|
||||
circleWidget->updateStatus();
|
||||
|
@ -215,7 +217,7 @@ void FriendWidget::moveToNewCircle()
|
|||
friendList->addCircleWidget(this);
|
||||
} else {
|
||||
const auto pk = frnd->getPublicKey();
|
||||
auto& s = Settings::getInstance();
|
||||
auto& s = settings;
|
||||
auto circleId = s.addCircle();
|
||||
s.setFriendCircleID(pk, circleId);
|
||||
}
|
||||
|
@ -226,13 +228,13 @@ void FriendWidget::removeFromCircle()
|
|||
const auto frnd = chatroom->getFriend();
|
||||
CircleWidget* circleWidget;
|
||||
FriendListWidget* friendList;
|
||||
std::tie(circleWidget, friendList) = getCircleAndFriendList(frnd, this);
|
||||
std::tie(circleWidget, friendList) = getCircleAndFriendList(frnd, this, settings);
|
||||
|
||||
if (friendList != nullptr) {
|
||||
friendList->moveWidget(this, frnd->getStatus(), true);
|
||||
} else {
|
||||
const auto pk = frnd->getPublicKey();
|
||||
auto& s = Settings::getInstance();
|
||||
auto& s = settings;
|
||||
s.setFriendCircleID(pk, -1);
|
||||
}
|
||||
|
||||
|
@ -245,8 +247,8 @@ void FriendWidget::moveToCircle(int newCircleId)
|
|||
{
|
||||
const auto frnd = chatroom->getFriend();
|
||||
const auto pk = frnd->getPublicKey();
|
||||
const auto oldCircleId = Settings::getInstance().getFriendCircleID(pk);
|
||||
auto& s = Settings::getInstance();
|
||||
const auto oldCircleId = settings.getFriendCircleID(pk);
|
||||
auto& s = settings;
|
||||
auto oldCircleWidget = CircleWidget::getFromID(oldCircleId);
|
||||
auto newCircleWidget = CircleWidget::getFromID(newCircleId);
|
||||
|
||||
|
@ -279,9 +281,9 @@ void FriendWidget::changeAutoAccept(bool enable)
|
|||
void FriendWidget::showDetails()
|
||||
{
|
||||
const auto frnd = chatroom->getFriend();
|
||||
const auto iabout = new AboutFriend(frnd, &Settings::getInstance());
|
||||
const auto iabout = new AboutFriend(frnd, &settings);
|
||||
std::unique_ptr<IAboutFriend> about = std::unique_ptr<IAboutFriend>(iabout);
|
||||
const auto aboutUser = new AboutFriendForm(std::move(about), this);
|
||||
const auto aboutUser = new AboutFriendForm(std::move(about), settings, this);
|
||||
connect(aboutUser, &AboutFriendForm::histroyRemoved, this, &FriendWidget::friendHistoryRemoved);
|
||||
aboutUser->show();
|
||||
}
|
||||
|
@ -313,7 +315,7 @@ void FriendWidget::updateStatusLight()
|
|||
statusPic.setPixmap(QPixmap(Status::getIconPath(frnd->getStatus(), event)));
|
||||
|
||||
if (event) {
|
||||
const Settings& s = Settings::getInstance();
|
||||
const Settings& s = settings;
|
||||
const uint32_t circleId = s.getFriendCircleID(frnd->getPublicKey());
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||
if (circleWidget) {
|
||||
|
@ -383,7 +385,7 @@ QString FriendWidget::getNameItem() const
|
|||
QDateTime FriendWidget::getLastActivity() const
|
||||
{
|
||||
const auto frnd = chatroom->getFriend();
|
||||
return Settings::getInstance().getFriendActivity(frnd->getPublicKey());
|
||||
return settings.getFriendActivity(frnd->getPublicKey());
|
||||
}
|
||||
|
||||
QWidget *FriendWidget::getWidget()
|
||||
|
|
|
@ -29,12 +29,13 @@ class FriendChatroom;
|
|||
class QPixmap;
|
||||
class MaskablePixmapWidget;
|
||||
class CircleWidget;
|
||||
class Settings;
|
||||
|
||||
class FriendWidget : public GenericChatroomWidget, public IFriendListItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FriendWidget(std::shared_ptr<FriendChatroom> chatform_, bool compact_);
|
||||
FriendWidget(std::shared_ptr<FriendChatroom> chatform_, bool compact_, Settings&);
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* event) final;
|
||||
void setAsActiveChatroom() final;
|
||||
|
@ -85,4 +86,5 @@ private slots:
|
|||
public:
|
||||
std::shared_ptr<FriendChatroom> chatroom;
|
||||
bool isDefaultAvatar;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -25,9 +25,10 @@
|
|||
#include <QBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
|
||||
GenericChatroomWidget::GenericChatroomWidget(bool compact_, QWidget* parent)
|
||||
GenericChatroomWidget::GenericChatroomWidget(bool compact_, Settings& settings_, QWidget* parent)
|
||||
: GenericChatItemWidget(compact_, parent)
|
||||
, active{false}
|
||||
, settings{settings_}
|
||||
{
|
||||
// avatar
|
||||
QSize size;
|
||||
|
@ -47,8 +48,7 @@ GenericChatroomWidget::GenericChatroomWidget(bool compact_, QWidget* parent)
|
|||
nameLabel->setForegroundRole(QPalette::WindowText);
|
||||
nameLabel->setObjectName("nameLabelObj");
|
||||
|
||||
Settings& s = Settings::getInstance();
|
||||
connect(&s, &Settings::compactLayoutChanged, this, &GenericChatroomWidget::compactChange);
|
||||
connect(&settings, &Settings::compactLayoutChanged, this, &GenericChatroomWidget::compactChange);
|
||||
|
||||
setAutoFillBackground(true);
|
||||
reloadTheme();
|
||||
|
@ -158,7 +158,7 @@ QString GenericChatroomWidget::getTitle() const
|
|||
|
||||
void GenericChatroomWidget::reloadTheme()
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet("genericChatRoomWidget/genericChatRoomWidget.css"));
|
||||
setStyleSheet(Style::getStylesheet("genericChatRoomWidget/genericChatRoomWidget.css", settings));
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::activate()
|
||||
|
|
|
@ -29,11 +29,13 @@ class ContentLayout;
|
|||
class Friend;
|
||||
class Group;
|
||||
class Contact;
|
||||
class Settings;
|
||||
|
||||
class GenericChatroomWidget : public GenericChatItemWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GenericChatroomWidget(bool compact, QWidget* parent = nullptr);
|
||||
explicit GenericChatroomWidget(bool compact, Settings&, QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
virtual void setAsActiveChatroom() = 0;
|
||||
|
@ -83,4 +85,5 @@ protected:
|
|||
MaskablePixmapWidget* avatar;
|
||||
CroppingLabel* statusMessageLabel;
|
||||
bool active;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
#include "src/widget/widget.h"
|
||||
#include "tool/croppinglabel.h"
|
||||
|
||||
GroupWidget::GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact_)
|
||||
: GenericChatroomWidget(compact_)
|
||||
GroupWidget::GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact_, Settings& settings_)
|
||||
: GenericChatroomWidget(compact_, settings_)
|
||||
, groupId{chatroom_->getGroup()->getPersistentId()}
|
||||
, chatroom{chatroom_}
|
||||
{
|
||||
|
|
|
@ -27,11 +27,13 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
class Settings;
|
||||
|
||||
class GroupWidget final : public GenericChatroomWidget, public IFriendListItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact);
|
||||
GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact, Settings&);
|
||||
~GroupWidget();
|
||||
void setAsInactiveChatroom() final;
|
||||
void setAsActiveChatroom() final;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user