From dfead668759525cf0bd833cb873b694cbf05905d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 26 Apr 2010 16:46:56 +0200 Subject: Encodings management --- src/application.cpp | 4 +++- src/mainwindow.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- src/mainwindow.h | 7 ++++++- src/rekonq.kcfg | 3 +++ 4 files changed, 59 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/application.cpp b/src/application.cpp index b28055f7..d2754ec1 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -411,9 +411,11 @@ void Application::updateConfiguration() else view->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectRightTab); - // =========== Fonts ============== + // =========== Encodings & Fonts ============== QWebSettings *defaultSettings = QWebSettings::globalSettings(); + defaultSettings->setDefaultTextEncoding( ReKonfig::defaultEncoding() ); + int fnSize = ReKonfig::fontSize(); int minFnSize = ReKonfig::minFontSize(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 03a6194a..6355e6d8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -104,6 +104,7 @@ MainWindow::MainWindow() , m_bookmarksPanel(0) , m_webInspectorPanel(0) , m_historyBackMenu(0) + , m_encodingMenu( new KMenu(this) ) , m_mainBar( new KToolBar( QString("MainToolBar"), this, Qt::TopToolBarArea, true, true, true) ) , m_bmBar( new KToolBar( QString("BookmarkToolBar"), this, Qt::TopToolBarArea, true, false, true) ) , m_popup( new KPassivePopup(this) ) @@ -161,6 +162,7 @@ MainWindow::~MainWindow() Application::bookmarkProvider()->removeToolBar(m_bmBar); Application::instance()->removeMainWindow(this); delete m_popup; + delete m_encodingMenu; } @@ -396,6 +398,7 @@ void MainWindow::setupActions() actionCollection()->addAction( QLatin1String("detach_tab"), a); connect(a, SIGNAL(triggered(bool)), m_view->tabBar(), SLOT(detachTab()) ); + // ----------------------- Bookmarks ToolBar Action -------------------------------------- QAction *qa; @@ -414,6 +417,14 @@ void MainWindow::setupActions() bmMenu->setIcon(KIcon("bookmarks")); bmMenu->setDelayed(false); actionCollection()->addAction(QLatin1String("bookmarksActionMenu"), bmMenu); + + + // ---------------- Encodings ----------------------------------- + a = new KAction( KIcon("character-set"), i18n("Set Encoding"), this); + actionCollection()->addAction( QLatin1String("encodings"), a); + a->setMenu(m_encodingMenu); + connect(m_encodingMenu, SIGNAL(aboutToShow()), this, SLOT( populateEncodingMenu() ) ); + connect(m_encodingMenu, SIGNAL(triggered(QAction *)), this, SLOT( setEncoding(QAction *) )); } @@ -482,6 +493,8 @@ void MainWindow::setupTools() toolsMenu->addSeparator(); + toolsMenu->addAction(actionByName(QLatin1String("encodings"))); + helpMenu()->setIcon(KIcon("help-browser")); toolsMenu->addAction(helpMenu()->menuAction()); toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Preferences))); @@ -1174,8 +1187,6 @@ void MainWindow::aboutToShowBackMenu() if(pivot >= 8) offset = pivot - 8; - - for(int i = listCount - 1; i>=0; --i) { QWebHistoryItem item = historyList.at(i); @@ -1202,3 +1213,37 @@ void MainWindow::openActionUrl(QAction *action) history->goToItem( history->itemAt(index) ); } + + +void MainWindow::setEncoding(QAction *qa) +{ + QString currentCodec = qa->text().toLatin1(); + currentCodec = currentCodec.remove('&'); + kDebug() << currentCodec; + QWebSettings::globalSettings()->setDefaultTextEncoding( currentCodec ); + ReKonfig::setDefaultEncoding(currentCodec); +} + + +void MainWindow::populateEncodingMenu() +{ + QList byteCodecs = QTextCodec::availableCodecs(); + QStringList codecs; + Q_FOREACH(const QByteArray &b, byteCodecs) + { + codecs << QString(b); + } + codecs.sort(); + + QString currentCodec = ReKonfig::defaultEncoding(); + kDebug() << "Current Codec: " << currentCodec; + + m_encodingMenu->clear(); + Q_FOREACH(const QString &codec, codecs) + { + QAction *action = m_encodingMenu->addAction(codec); + action->setCheckable(true); + if (currentCodec == codec) + action->setChecked(true); + } +} \ No newline at end of file diff --git a/src/mainwindow.h b/src/mainwindow.h index 5c525e26..7129de80 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -157,6 +157,10 @@ private slots: void aboutToShowBackMenu(); void openActionUrl(QAction *action); + // encodings + void setEncoding(QAction *); + void populateEncodingMenu(); + private: MainView *m_view; FindBar *m_findBar; @@ -167,7 +171,8 @@ private: KAction *m_stopReloadAction; KMenu *m_historyBackMenu; - + KMenu *m_encodingMenu; + KToolBar *m_mainBar; KToolBar *m_bmBar; diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index dd46624f..3658b324 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -29,6 +29,9 @@ 0 + + UTF-8 + -- cgit v1.2.1