Put setting loading in a slot so it can be used at startup and when
preferences change
This commit is contained in:
		
					parent
					
						
							
								929a099760
							
						
					
				
			
			
				commit
				
					
						1b9c0adaa8
					
				
			
		
					 2 changed files with 33 additions and 22 deletions
				
			
		| 
						 | 
					@ -68,6 +68,8 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
    qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
 | 
					    qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
 | 
				
			||||||
    qRegisterMetaType<DanbooruPost::Rating>();
 | 
					    qRegisterMetaType<DanbooruPost::Rating>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    loadSettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO Configurable
 | 
					    // TODO Configurable
 | 
				
			||||||
    m_cache = new KImageCache(qApp->applicationName(), DanbooruSettings::self()->cacheSize());
 | 
					    m_cache = new KImageCache(qApp->applicationName(), DanbooruSettings::self()->cacheSize());
 | 
				
			||||||
    m_service->setImageCache(m_cache);
 | 
					    m_service->setImageCache(m_cache);
 | 
				
			||||||
| 
						 | 
					@ -129,6 +131,17 @@ DanbooruMainWindow::~DanbooruMainWindow()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DanbooruMainWindow::loadSettings()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    m_service->setBlacklist(DanbooruSettings::self()->tagBlacklist());
 | 
				
			||||||
 | 
					    m_service->setMaxPosts(DanbooruSettings::self()->maxPosts());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_service->setMaximumAllowedRating(ratingMap.value(DanbooruSettings::self()->maxRating()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_service->setMaxPosts(DanbooruSettings::self()->maxPosts());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruMainWindow::setupActions()
 | 
					void DanbooruMainWindow::setupActions()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -174,7 +187,7 @@ void DanbooruMainWindow::downloadPosts()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO Pick from configuration
 | 
					    // TODO Pick from configuration
 | 
				
			||||||
    m_service->getPostList(1, QStringList(), 10);
 | 
					    m_service->getPostList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,15 +198,7 @@ void DanbooruMainWindow::optionsPreferences()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dialog->addPage(new GeneralPage(DanbooruSettings::self(), this), i18n("General"),
 | 
					    dialog->addPage(new GeneralPage(DanbooruSettings::self(), this), i18n("General"),
 | 
				
			||||||
        "table");
 | 
					        "table");
 | 
				
			||||||
    connect(dialog, &KConfigDialog::settingsChanged, [this](){
 | 
					    connect(dialog, &KConfigDialog::settingsChanged, this, &DanbooruMainWindow::loadSettings);
 | 
				
			||||||
        auto preferences = DanbooruSettings::self();
 | 
					 | 
				
			||||||
        qDebug() << preferences->boards();
 | 
					 | 
				
			||||||
        qDebug() << preferences->cacheSize();
 | 
					 | 
				
			||||||
        qDebug() << preferences->maxPosts();
 | 
					 | 
				
			||||||
        qDebug() << preferences->tagBlacklist();
 | 
					 | 
				
			||||||
        qDebug() << preferences->maxRating();
 | 
					 | 
				
			||||||
        m_service->setMaximumAllowedRating(ratingMap.value(preferences->maxRating()));
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    dialog->show();
 | 
					    dialog->show();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,6 +50,15 @@ class DanbooruConnectWidget;
 | 
				
			||||||
class DanbooruMainWindow : public KXmlGuiWindow
 | 
					class DanbooruMainWindow : public KXmlGuiWindow
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    QQuickWidget *m_view;
 | 
				
			||||||
 | 
					    DanbooruPostModel *m_model;
 | 
				
			||||||
 | 
					    DanbooruService *m_service;
 | 
				
			||||||
 | 
					    DanbooruConnectWidget *m_connectWidget;
 | 
				
			||||||
 | 
					    KImageCache *m_cache;
 | 
				
			||||||
 | 
					    static QHash<int, DanbooruPost::Rating> ratingMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Default Constructor
 | 
					     * Default Constructor
 | 
				
			||||||
| 
						 | 
					@ -61,22 +70,19 @@ public:
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    virtual ~DanbooruMainWindow();
 | 
					    virtual ~DanbooruMainWindow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private Q_SLOTS:
 | 
					 | 
				
			||||||
    void connectToBoard();
 | 
					 | 
				
			||||||
    void downloadPosts();
 | 
					 | 
				
			||||||
    void optionsPreferences();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void setupActions();
 | 
					    void setupActions();
 | 
				
			||||||
    void setupConnections();
 | 
					    void setupConnections();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private Q_SLOTS:
 | 
				
			||||||
    QQuickWidget *m_view;
 | 
					    void connectToBoard();
 | 
				
			||||||
    DanbooruPostModel *m_model;
 | 
					    void downloadPosts();
 | 
				
			||||||
    DanbooruService *m_service;
 | 
					    void optionsPreferences();
 | 
				
			||||||
    DanbooruConnectWidget *m_connectWidget;
 | 
					    void loadSettings();
 | 
				
			||||||
    KImageCache *m_cache;
 | 
					
 | 
				
			||||||
    static QHash<int, DanbooruPost::Rating> ratingMap;
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
} // namespace Danbooru
 | 
					} // namespace Danbooru
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue