root / trunk / client / gui_qt / WidgetConfigAutoImport.cpp @ 1794
History | View | Annotate | Download (6.3 KB)
| 1 |
#include "WidgetConfigAutoImport.h" |
|---|---|
| 2 |
#include "ui_WidgetConfigAutoImport.h" |
| 3 |
#include "ConfigGuiOpts.h" |
| 4 |
|
| 5 |
WidgetConfigAutoImport::WidgetConfigAutoImport(MainWindow *mainwindow, QNNTPGrabGlue *glue, QWidget *parent) : |
| 6 |
QWidget(parent), |
| 7 |
ui(new Ui::WidgetConfigAutoImport), |
| 8 |
auto_import(mainwindow, glue) |
| 9 |
{
|
| 10 |
ui->setupUi(this); |
| 11 |
|
| 12 |
this->glue = glue; |
| 13 |
|
| 14 |
model = new QDirModel(); |
| 15 |
//model->setRootPath(QDir::rootPath());
|
| 16 |
model->setReadOnly(true);
|
| 17 |
model->setResolveSymlinks(true);
|
| 18 |
model->setFilter(QDir::Dirs | QDir::AllDirs | QDir::Drives | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot); |
| 19 |
|
| 20 |
ui->treeViewAutoImportLocal->setModel(model); |
| 21 |
ui->treeViewAutoImportLocal->setHeaderHidden(true);
|
| 22 |
ui->treeViewAutoImportLocal->header()->hideSection(1);
|
| 23 |
ui->treeViewAutoImportLocal->header()->hideSection(2);
|
| 24 |
ui->treeViewAutoImportLocal->header()->hideSection(3);
|
| 25 |
|
| 26 |
connect(ui->chkEnableAutoImportLocal, SIGNAL(toggled(bool)), SLOT(chkEnableAutoImportLocal_clicked(bool))); |
| 27 |
connect(ui->treeViewAutoImportLocal, SIGNAL(clicked(QModelIndex)), SLOT(treeViewAutoImportLocal_clicked(QModelIndex))); |
| 28 |
connect(ui->radMoveFileAfterImport, SIGNAL(toggled(bool)), SLOT(radMoveFileAfterImport_toggled(bool))); |
| 29 |
|
| 30 |
if (glue->getIsStandalone()) {
|
| 31 |
ui->chkEnableAutoImportServer->hide(); |
| 32 |
ui->groupBoxAutoImportServer->hide(); |
| 33 |
} else {
|
| 34 |
ConfigGuiOpts opts; |
| 35 |
|
| 36 |
ui->chkEnableAutoImportLocal->setChecked(opts.getEnableAutoImport()); |
| 37 |
|
| 38 |
//QModelIndex idx = model->setRootPath(opts.getAutoImportDirectory());
|
| 39 |
QModelIndex idx = model->index(opts.getAutoImportDirectory()); |
| 40 |
ui->treeViewAutoImportLocal->scrollTo(idx); |
| 41 |
ui->treeViewAutoImportLocal->setCurrentIndex(idx); |
| 42 |
|
| 43 |
connect(ui->chkEnableAutoImportServer, SIGNAL(toggled(bool)), SLOT(chkEnableAutoImportServer_clicked(bool))); |
| 44 |
connect(ui->editAutoImportServer, SIGNAL(textChanged(QString)), SLOT(editAutoImportServer_textChanged(QString))); |
| 45 |
connect(ui->btnAutoImportServerApply, SIGNAL(clicked()), SLOT(btnAutoImportServerApply_clicked())); |
| 46 |
} |
| 47 |
|
| 48 |
configChanged(); |
| 49 |
connect(glue, SIGNAL(configChanged()), SLOT(configChanged())); |
| 50 |
} |
| 51 |
|
| 52 |
WidgetConfigAutoImport::~WidgetConfigAutoImport() |
| 53 |
{
|
| 54 |
delete model; |
| 55 |
delete ui; |
| 56 |
} |
| 57 |
|
| 58 |
void WidgetConfigAutoImport::changeEvent(QEvent *e)
|
| 59 |
{
|
| 60 |
QWidget::changeEvent(e); |
| 61 |
switch (e->type()) {
|
| 62 |
case QEvent::LanguageChange: |
| 63 |
ui->retranslateUi(this); |
| 64 |
break;
|
| 65 |
default:
|
| 66 |
break;
|
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
void WidgetConfigAutoImport::configChanged()
|
| 71 |
{
|
| 72 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
| 73 |
|
| 74 |
ui->radMoveFileAfterImport->setChecked(opts.move_file_after_auto_import); |
| 75 |
ui->radDeleteFileAfterImport->setChecked(!opts.move_file_after_auto_import); |
| 76 |
|
| 77 |
if (glue->getIsStandalone()) {
|
| 78 |
/* Update the local configuration */
|
| 79 |
if (ui->chkEnableAutoImportLocal->isChecked() != opts.enable_auto_import) {
|
| 80 |
ui->chkEnableAutoImportLocal->setChecked(opts.enable_auto_import); |
| 81 |
if (opts.enable_auto_import) {
|
| 82 |
//QModelIndex idx = model->setRootPath(opts.auto_import_directory);
|
| 83 |
QModelIndex idx = model->index(opts.auto_import_directory); |
| 84 |
ui->treeViewAutoImportLocal->scrollTo(idx); |
| 85 |
ui->treeViewAutoImportLocal->setCurrentIndex(idx); |
| 86 |
} |
| 87 |
|
| 88 |
#ifdef Q_OS_MAC
|
| 89 |
/* Directory monitoring using GLib doesn't work on OSX
|
| 90 |
* so we use Qt to perform directory monitoring */ |
| 91 |
if (opts.enable_auto_import) {
|
| 92 |
auto_import.enableWatch(opts.auto_import_directory); |
| 93 |
} else {
|
| 94 |
auto_import.disableWatch(); |
| 95 |
} |
| 96 |
#endif
|
| 97 |
} |
| 98 |
} else {
|
| 99 |
/* Update the remote configuration */
|
| 100 |
if (ui->chkEnableAutoImportServer->isChecked() != opts.enable_auto_import) {
|
| 101 |
ui->chkEnableAutoImportServer->setChecked(opts.enable_auto_import); |
| 102 |
if (opts.enable_auto_import) {
|
| 103 |
ui->editAutoImportServer->setText(opts.auto_import_directory); |
| 104 |
ui->btnAutoImportServerApply->setEnabled(false);
|
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
void WidgetConfigAutoImport::chkEnableAutoImportLocal_clicked(bool toggled) |
| 111 |
{
|
| 112 |
if (glue->getIsStandalone()) {
|
| 113 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
| 114 |
if (toggled != opts.enable_auto_import) {
|
| 115 |
opts.enable_auto_import = toggled; |
| 116 |
glue->configSetOpts(opts); |
| 117 |
} |
| 118 |
} else {
|
| 119 |
ConfigGuiOpts opts; |
| 120 |
if (toggled != opts.getEnableAutoImport()) {
|
| 121 |
opts.setEnableAutoImport(toggled); |
| 122 |
|
| 123 |
if (toggled) {
|
| 124 |
auto_import.enableWatch(opts.getAutoImportDirectory()); |
| 125 |
} else {
|
| 126 |
auto_import.disableWatch(); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
void WidgetConfigAutoImport::treeViewAutoImportLocal_clicked(QModelIndex idx)
|
| 133 |
{
|
| 134 |
QString path = model->filePath(idx); |
| 135 |
|
| 136 |
if (glue->getIsStandalone()) {
|
| 137 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
| 138 |
if (opts.auto_import_directory != path) {
|
| 139 |
opts.auto_import_directory = path; |
| 140 |
glue->configSetOpts(opts); |
| 141 |
} |
| 142 |
} else {
|
| 143 |
ConfigGuiOpts opts; |
| 144 |
if (path != opts.getAutoImportDirectory()) {
|
| 145 |
opts.setAutoImportDirectory(path); |
| 146 |
|
| 147 |
auto_import.enableWatch(opts.getAutoImportDirectory()); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
void WidgetConfigAutoImport::radMoveFileAfterImport_toggled(bool toggled) |
| 153 |
{
|
| 154 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
| 155 |
if (opts.move_file_after_auto_import != toggled) {
|
| 156 |
opts.move_file_after_auto_import = toggled; |
| 157 |
glue->configSetOpts(opts); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
void WidgetConfigAutoImport::chkEnableAutoImportServer_clicked(bool toggled) |
| 162 |
{
|
| 163 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
| 164 |
if (toggled != opts.enable_auto_import) {
|
| 165 |
opts.enable_auto_import = toggled; |
| 166 |
glue->configSetOpts(opts); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
void WidgetConfigAutoImport::editAutoImportServer_textChanged(QString text)
|
| 171 |
{
|
| 172 |
Q_UNUSED(text); |
| 173 |
ui->btnAutoImportServerApply->setEnabled(true);
|
| 174 |
} |
| 175 |
|
| 176 |
void WidgetConfigAutoImport::btnAutoImportServerApply_clicked()
|
| 177 |
{
|
| 178 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
| 179 |
if (opts.auto_import_directory != ui->editAutoImportServer->text()) {
|
| 180 |
opts.auto_import_directory = ui->editAutoImportServer->text(); |
| 181 |
glue->configSetOpts(opts); |
| 182 |
} |
| 183 |
} |
NNTPGrab

