2018-06-26 14:09:39 +02:00
# include "ModerationPage.hpp"
# include "Application.hpp"
2018-07-03 14:59:18 +02:00
# include "controllers/moderationactions/ModerationActionModel.hpp"
# include "controllers/moderationactions/ModerationActions.hpp"
2018-06-26 14:09:39 +02:00
# include "controllers/taggedusers/TaggedUsersController.hpp"
# include "controllers/taggedusers/TaggedUsersModel.hpp"
2018-06-28 19:46:45 +02:00
# include "singletons/Logging.hpp"
# include "singletons/Paths.hpp"
2018-06-26 14:09:39 +02:00
# include "util/LayoutCreator.hpp"
# include "widgets/helper/EditableModelView.hpp"
2018-04-27 22:11:19 +02:00
2018-07-03 14:59:18 +02:00
# include <QFileDialog>
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 {
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-06-26 17:06:17 +02:00
LayoutCreator < ModerationPage > layoutCreator ( this ) ;
2018-01-13 03:06:10 +01:00
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-06-06 20:30:11 +02:00
app - > settings - > logPath . connect ( [ app , created ] ( const QString & logPath , auto ) mutable {
if ( logPath = = " " ) {
created - > setText ( " Logs are saved to " +
2018-06-21 13:02:34 +02:00
CreateLink ( app - > paths - > messageLogDirectory , true ) ) ;
2018-06-06 20:30:11 +02:00
} else {
created - > setText ( " Logs are saved to " + CreateLink ( 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-05-26 20:25:00 +02:00
logs - > addStretch ( 1 ) ;
2018-06-06 20:30:11 +02:00
auto selectDir = logs . emplace < QPushButton > ( " Set custom logpath " ) ;
// Setting custom logpath
QObject : : connect ( selectDir . getElement ( ) , & QPushButton : : clicked , this , [ this ] ( ) {
auto app = getApp ( ) ;
auto dirName = QFileDialog : : getExistingDirectory ( this ) ;
app - > settings - > logPath = dirName ;
} ) ;
// Reset custom logpath
auto resetDir = logs . emplace < QPushButton > ( " Reset logpath " ) ;
QObject : : connect ( resetDir . getElement ( ) , & QPushButton : : clicked , this , [ ] ( ) {
auto app = getApp ( ) ;
app - > settings - > logPath = " " ;
} ) ;
// Logs end
2018-05-26 20:25:00 +02:00
}
2018-04-26 23:07:02 +02:00
2018-07-03 14:59:18 +02:00
auto modMode = tabs . appendTab ( new QVBoxLayout , " Moderation buttons " ) ;
2018-05-26 20:25:00 +02:00
{
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-07-03 14:59:18 +02:00
EditableModelView * view =
modMode . emplace < EditableModelView > ( app - > moderationActions - > createModel ( nullptr ) )
. getElement ( ) ;
2018-06-28 19:38:57 +02:00
2018-07-03 14:59:18 +02:00
view - > setTitles ( { " Actions " } ) ;
view - > getTableView ( ) - > horizontalHeader ( ) - > setSectionResizeMode ( QHeaderView : : Fixed ) ;
view - > getTableView ( ) - > horizontalHeader ( ) - > setSectionResizeMode ( 0 , QHeaderView : : Stretch ) ;
2018-06-28 19:38:57 +02:00
2018-07-03 14:59:18 +02:00
view - > addButtonPressed . connect ( [ ] {
getApp ( ) - > moderationActions - > items . appendItem ( ModerationAction ( " /timeout {user} 300 " ) ) ;
} ) ;
2018-05-26 20:25:00 +02:00
/*auto taggedUsers = tabs.appendTab(new QVBoxLayout, "Tagged users");
{
2018-06-26 17:06:17 +02:00
EditableModelView * view = * taggedUsers . emplace < EditableModelView > (
2018-05-26 20:25:00 +02:00
app - > taggedUsers - > createModel ( nullptr ) ) ;
view - > setTitles ( { " Name " } ) ;
view - > getTableView ( ) - > horizontalHeader ( ) - > setStretchLastSection ( true ) ;
view - > addButtonPressed . connect ( [ ] {
getApp ( ) - > taggedUsers - > users . appendItem (
2018-06-26 17:06:17 +02:00
TaggedUser ( ProviderId : : Twitch , " example " , " xD " ) ) ;
2018-05-26 20:25:00 +02:00
} ) ;
} */
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 chatterino