2018-01-12 23:09:05 +01:00
# include "moderationpage.hpp"
2018-04-27 22:11:19 +02:00
# include "application.hpp"
2018-05-15 19:44:58 +02:00
# include "singletons/loggingmanager.hpp"
2018-05-26 20:25:00 +02:00
# include "controllers/taggedusers/taggeduserscontroller.hpp"
# include "controllers/taggedusers/taggedusersmodel.hpp"
2018-04-27 22:11:19 +02:00
# include "singletons/pathmanager.hpp"
# include "util/layoutcreator.hpp"
2018-05-26 20:25:00 +02:00
# include "widgets/helper/editablemodelview.hpp"
2018-04-27 22:11:19 +02:00
2018-05-26 20:25:00 +02:00
# include <QFormLayout>
2018-01-24 15:08:22 +01:00
# include <QGroupBox>
2018-01-13 03:06:10 +01:00
# include <QHBoxLayout>
2018-05-26 20:25:00 +02:00
# include <QHeaderView>
2018-01-13 03:06:10 +01:00
# include <QLabel>
# include <QListView>
# include <QPushButton>
2018-05-26 20:25:00 +02:00
# include <QTableView>
2018-01-13 03:06:10 +01:00
# include <QTextEdit>
# include <QVBoxLayout>
2018-01-12 23:09:05 +01:00
namespace chatterino {
namespace widgets {
namespace settingspages {
2018-03-24 16:55:28 +01:00
2018-04-26 23:07:02 +02:00
inline QString CreateLink ( const QString & url , bool file = false )
{
if ( file ) {
return QString ( " <a href= \" file:/// " + url + " \" ><span style= \" color: white; \" > " + url +
" </span></a> " ) ;
}
return QString ( " <a href= \" " + url + " \" ><span style= \" color: white; \" > " + url + " </span></a> " ) ;
}
2018-01-12 23:09:05 +01:00
ModerationPage : : ModerationPage ( )
2018-01-13 03:06:10 +01:00
: SettingsPage ( " Moderation " , " " )
2018-01-12 23:09:05 +01:00
{
2018-04-27 22:11:19 +02:00
auto app = getApp ( ) ;
2018-01-13 03:06:10 +01:00
util : : LayoutCreator < ModerationPage > layoutCreator ( this ) ;
2018-05-26 20:25:00 +02:00
auto tabs = layoutCreator . emplace < QTabWidget > ( ) ;
auto logs = tabs . appendTab ( new QVBoxLayout , " Logs " ) ;
2018-01-13 03:06:10 +01:00
{
2018-04-26 23:07:02 +02:00
// Logs (copied from LoggingMananger)
2018-05-26 20:25:00 +02:00
auto created = logs . emplace < QLabel > ( ) ;
2018-05-15 19:44:58 +02:00
if ( app - > settings - > logPath = = " " ) {
created - > setText ( " Logs are saved to " +
CreateLink ( QCoreApplication : : applicationDirPath ( ) , true ) ) ;
} else {
created - > setText ( " Logs are saved to " + CreateLink ( app - > settings - > logPath , true ) ) ;
}
2018-04-26 23:07:02 +02:00
created - > setTextFormat ( Qt : : RichText ) ;
created - > setTextInteractionFlags ( Qt : : TextBrowserInteraction |
Qt : : LinksAccessibleByKeyboard |
Qt : : LinksAccessibleByKeyboard ) ;
created - > setOpenExternalLinks ( true ) ;
2018-05-26 20:25:00 +02:00
logs . append ( this - > createCheckBox ( " Enable logging " , app - > settings - > enableLogging ) ) ;
2018-04-26 23:07:02 +02:00
2018-06-05 13:16:20 +02:00
<
2018-05-26 20:25:00 +02:00
logs - > addStretch ( 1 ) ;
2018-05-15 19:44:58 +02:00
2018-05-16 01:39:08 +02:00
auto selectDir = layout . emplace < QPushButton > ( " Set custom logpath " ) ;
// Setting custom logpath
QObject : : connect ( selectDir . getElement ( ) , & QPushButton : : clicked , this , [
this , created , app , dirMemory = QString { app - > settings - > logPath }
] ( ) mutable {
auto dirName = QFileDialog : : getExistingDirectory ( this ) ;
created - > setText ( " Logs are saved to " + CreateLink ( dirName , true ) ) ;
if ( dirName = = " " & & dirMemory = = " " ) {
created - > setText (
" Logs are saved to " +
CreateLink ( QStandardPaths : : writableLocation ( QStandardPaths : : AppDataLocation ) ,
true ) ) ;
} else if ( dirName = = " " ) {
dirName = dirMemory ;
2018-05-15 19:44:58 +02:00
created - > setText ( " Logs are saved to " + CreateLink ( dirName , true ) ) ;
2018-05-16 01:39:08 +02:00
}
2018-05-15 19:44:58 +02:00
2018-05-16 01:39:08 +02:00
app - > settings - > logPath = dirName ;
dirMemory = dirName ;
app - > logging - > refreshLoggingPath ( ) ;
} ) ;
// Reset custom logpath
2018-05-15 19:44:58 +02:00
auto resetDir = layout . emplace < QPushButton > ( " Reset logpath " ) ;
QObject : : connect (
resetDir . getElement ( ) , & QPushButton : : clicked , this , [ this , created , app ] ( ) mutable {
app - > settings - > logPath = " " ;
2018-05-16 01:39:08 +02:00
created - > setText (
" Logs are saved to " +
CreateLink ( QStandardPaths : : writableLocation ( QStandardPaths : : AppDataLocation ) ,
true ) ) ;
2018-05-15 19:44:58 +02:00
app - > logging - > refreshLoggingPath ( ) ;
} ) ;
2018-04-26 23:07:02 +02:00
// Logs end
2018-05-26 20:25:00 +02:00
}
2018-04-26 23:07:02 +02:00
2018-05-26 20:25:00 +02:00
auto modMode = tabs . appendTab ( new QVBoxLayout , " Moderation mode " ) ;
{
2018-01-13 03:06:10 +01:00
// clang-format off
2018-05-26 20:25:00 +02:00
auto label = modMode . emplace < QLabel > ( " Click the moderation mod button (<img width='18' height='18' src=':/images/moderatormode_disabled.png'>) in a channel that you moderate to enable moderator mode.<br> " ) ;
2018-01-13 03:06:10 +01:00
label - > setWordWrap ( true ) ;
2018-01-24 15:08:22 +01:00
label - > setStyleSheet ( " color: #bbb " ) ;
2018-01-13 03:06:10 +01:00
// clang-format on
2018-05-26 20:25:00 +02:00
// auto form = modMode.emplace<QFormLayout>();
// {
// form->addRow("Action on timed out messages (unimplemented):",
// this->createComboBox({"Disable", "Hide"},
// app->settings->timeoutAction));
// }
2018-03-24 16:55:28 +01:00
2018-01-24 15:08:22 +01:00
auto modButtons =
2018-05-26 20:25:00 +02:00
modMode . emplace < QGroupBox > ( " Custom moderator buttons " ) . setLayoutType < QVBoxLayout > ( ) ;
2018-01-24 15:08:22 +01:00
{
auto label2 =
modButtons . emplace < QLabel > ( " One action per line. {user} will be replaced with the "
" username.<br>Example `/timeout {user} 120`<br> " ) ;
label2 - > setWordWrap ( true ) ;
2018-01-13 03:06:10 +01:00
2018-01-24 15:08:22 +01:00
auto text = modButtons . emplace < QTextEdit > ( ) . getElement ( ) ;
2018-01-17 14:14:31 +01:00
2018-04-27 22:11:19 +02:00
text - > setPlainText ( app - > settings - > moderationActions ) ;
2018-01-13 03:06:10 +01:00
2018-01-24 15:08:22 +01:00
QObject : : connect ( text , & QTextEdit : : textChanged , this ,
[ this ] { this - > itemsChangedTimer . start ( 200 ) ; } ) ;
2018-04-27 22:11:19 +02:00
QObject : : connect ( & this - > itemsChangedTimer , & QTimer : : timeout , this , [ text , app ] ( ) {
app - > settings - > moderationActions = text - > toPlainText ( ) ;
2018-01-24 15:08:22 +01:00
} ) ;
}
2018-05-26 20:25:00 +02:00
/*auto taggedUsers = tabs.appendTab(new QVBoxLayout, "Tagged users");
{
helper : : EditableModelView * view = * taggedUsers . emplace < helper : : EditableModelView > (
app - > taggedUsers - > createModel ( nullptr ) ) ;
view - > setTitles ( { " Name " } ) ;
view - > getTableView ( ) - > horizontalHeader ( ) - > setStretchLastSection ( true ) ;
view - > addButtonPressed . connect ( [ ] {
getApp ( ) - > taggedUsers - > users . appendItem (
controllers : : taggedusers : : TaggedUser ( ProviderId : : Twitch , " example " , " xD " ) ) ;
} ) ;
} */
2018-01-13 03:06:10 +01:00
}
// ---- misc
this - > itemsChangedTimer . setSingleShot ( true ) ;
2018-01-12 23:09:05 +01:00
}
2018-01-13 03:06:10 +01:00
2018-01-12 23:09:05 +01:00
} // namespace settingspages
} // namespace widgets
} // namespace chatterino