The complete source code of IdealIRC http://www.idealirc.org/
 
 
 
 
idealirc/IWin/IWinPrivate.cpp

100 lines
2.6 KiB

/*
* IdealIRC - Internet Relay Chat client
* Copyright (C) 2021 Tom-Andre Barstad.
* This software is licensed under the Software Attribution License.
* See LICENSE for more information.
*/
#include "IWinPrivate.h"
#include "IWinStatus.h"
#include "Script/Manager.h"
#include "IRCClient/IRCMember.h"
#include "MdiManager.h"
#include <ConfigMgr.h>
IWinPrivate::IWinPrivate(IWinStatus* statusParent, const QString& targetName)
: IWin(IWin::Type::Private, statusParent)
, status(statusParent)
, connection(statusParent->getConnection())
{
setButtonText(targetName);
layout = new QVBoxLayout();
view = new IIRCView();
input = new ILineEdit([this](int a, QString& b){ return tabComplete(a,b); });
layout->setMargin(0);
layout->setSpacing(2);
layout->addWidget(view);
layout->addWidget(input);
setLayout(layout);
setTabOrder(input, view);
view->setFocusPolicy(Qt::FocusPolicy::NoFocus);
connect(input, &ILineEdit::newLine,
this, &IWinPrivate::newLine);
connect(view, &IIRCView::customContextMenuRequested, [this](const QPoint& point){
menuSymbols.set("nickname", getButtonText().toStdString());
ScriptManager::instance()->contextMenuPopup(ScriptMenuType::Private, mapToGlobal(point), menuSymbols);
});
}
bool IWinPrivate::print(const PrintType ptype, const QString& text)
{
view->print(ptype, text);
MdiManager::instance().highlight(this, HL_Activity);
ConfigMgr& conf = ConfigMgr::instance();
if (conf.logging("Privates") == "1") {
QString path = conf.logging("Path");
if (path.isEmpty())
return true;
path += "/" + getButtonText() + ".log";
QByteArray out;
out.append(IIRCView::formatType(ptype, text));
out.append("\n");
QFile f(path);
if (!f.open(QIODevice::WriteOnly | QIODevice::Append))
return true;
f.write(out);
f.close();
}
return true;
}
void IWinPrivate::refreshWindowTitle()
{
QString target = getButtonText();
auto ptr = connection.getMember(target.toStdString());
if (!ptr)
setWindowTitle(target);
else {
const auto& prefix = ptr->prefix();
if (prefix.host().empty())
setWindowTitle(target);
else
setWindowTitle(QStringLiteral("%1 (%2@%3)")
.arg(target)
.arg(prefix.user().c_str())
.arg(prefix.host().c_str()));
}
}
void IWinPrivate::newLine(const QString& line)
{
InputHandler inHndl(connection);
inHndl.parse(*this, line);
}
int IWinPrivate::tabComplete(int index, QString& pattern)
{
if (pattern.isEmpty() || !connection.isOnline())
return 0;
if (connection.isChannelSymbol( pattern[0].toLatin1() ))
return connection.channelAutoComplete(index, pattern);
return 0;
}