1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Added support for creating and deleting new profiles

This commit is contained in:
nowrep 2011-04-04 19:29:03 +02:00
parent 1d8cb36148
commit 23c1a80165
6 changed files with 114 additions and 19 deletions

View File

@ -48,11 +48,8 @@
#include "clickablelabel.h"
const QString QupZilla::VERSION = "0.9.9";
#ifdef Q_WS_X11
const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM dd yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss");
#else
const QString QupZilla::BUILDTIME = __DATE__" "__TIME__;
#endif
//const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM d yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss");
const QString QupZilla::BUILDTIME = __DATE__" "__TIME__;
const QString QupZilla::AUTHOR = "nowrep";
const QString QupZilla::COPYRIGHT = "2010-2011";
const QString QupZilla::WWWADDRESS = "http://qupzilla.ic.cz";

View File

@ -49,7 +49,7 @@ void AboutDialog::showAbout()
m_aboutHtml.append(tr("<p><b>Application version %1</b><br/>").arg(QupZilla::VERSION));
m_aboutHtml.append(tr("<b>WebKit version %1</b></p>").arg(QupZilla::WEBKITVERSION));
m_aboutHtml.append(tr("<p>&copy; %1 %2<br/>All rights reserved.<br/>").arg(QupZilla::COPYRIGHT, QupZilla::AUTHOR));
m_aboutHtml.append(tr("Build time: %1 </p>").arg(QupZilla::BUILDTIME));
m_aboutHtml.append(tr("<small>Build time: %1 </small></p>").arg(QupZilla::BUILDTIME));
m_aboutHtml.append(QString("<p><a href=%1>%1</a></p>").arg(QupZilla::WWWADDRESS));
m_aboutHtml.append("<p>"+mApp->getWindow()->weView()->webPage()->userAgentForUrl(QUrl())+"</p>");
m_aboutHtml.append("</div>");

View File

@ -31,6 +31,35 @@
#include "pluginproxy.h"
#include "sslmanager.h"
bool removeFile(QString fullFileName)
{
QFile f(fullFileName);
if (f.exists())
return f.remove();
else return false;
}
void removeDir(const QString d)
{
QDir dir(d);
if (dir.exists())
{
const QFileInfoList list = dir.entryInfoList();
QFileInfo fi;
for (int l = 0; l < list.size(); l++)
{
fi = list.at(l);
if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..")
removeDir(fi.absoluteFilePath());
else if (fi.isFile())
removeFile(fi.absoluteFilePath());
}
dir.rmdir(d);
}
}
Preferences::Preferences(QupZilla* mainClass, QWidget* parent) :
QDialog(parent)
,ui(new Ui::Preferences)
@ -48,6 +77,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) :
ui->homepage->setText(m_homepage);
ui->newTabUrl->setText(m_newTabUrl);
int afterLaunch = settings.value("afterLaunch",1).toInt();
settings.endGroup();
ui->afterLaunch->setCurrentIndex(afterLaunch);
ui->newTabFrame->setVisible(false);
@ -64,10 +94,21 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) :
connect(ui->newTabUseActual, SIGNAL(clicked()), this, SLOT(useActualNewTab()));
//PROFILES
ui->startPRofile->setEnabled(false);
ui->createProfile->setEnabled(false);
ui->deleteProfile->setEnabled(false);
settings.endGroup();
m_actProfileName = mApp->getActiveProfil();
m_actProfileName = m_actProfileName.left(m_actProfileName.length()-1);
m_actProfileName = m_actProfileName.mid(m_actProfileName.lastIndexOf("/"));
m_actProfileName.remove("/");
ui->startProfile->addItem(m_actProfileName);
QDir profilesDir(QDir::homePath()+"/.qupzilla/profiles/");
QStringList list_ = profilesDir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
foreach (QString name, list_) {
if (m_actProfileName == name)
continue;
ui->startProfile->addItem(name);
}
connect(ui->createProfile, SIGNAL(clicked()), this, SLOT(createProfile()));
connect(ui->deleteProfile, SIGNAL(clicked()), this, SLOT(deleteProfile()));
connect(ui->startProfile, SIGNAL(currentIndexChanged(QString)), this, SLOT(startProfileIndexChanged(QString)));
//WINDOW
settings.beginGroup("Browser-View-Settings");
@ -388,6 +429,45 @@ void Preferences::buttonClicked(QAbstractButton* button)
}
}
void Preferences::createProfile()
{
QString name = QInputDialog::getText(this, tr("New Profile"), tr("Enter the new profile's name:"));
if (name.contains("/") || name.contains("\\"))
return;
QDir dir(QDir::homePath()+"/.qupzilla/profiles/");
if (QDir(dir.absolutePath() + "/" + name).exists()) {
QMessageBox::warning(this, tr("Error!"), tr("This profile already exists!"));
return;
}
if (!dir.mkdir(name)) {
QMessageBox::warning(this, tr("Error!"), tr("Cannot create profile directory!"));
return;
}
dir.cd(name);
QFile(mApp->DATADIR+"data/default/profiles/default/browsedata.db").copy(dir.absolutePath()+"/browsedata.db");
QFile(mApp->DATADIR+"data/default/profiles/default/background.png").copy(dir.absolutePath()+"/background.png");
ui->startProfile->insertItem(0, name);
ui->startProfile->setCurrentIndex(0);
}
void Preferences::deleteProfile()
{
QString name = ui->startProfile->currentText();
QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"),
tr("Are you sure to permanently delete \"%1\" profile? This action cannot be undone!").arg(name), QMessageBox::Yes | QMessageBox::No);
if (button != QMessageBox::Yes)
return;
removeDir(QDir::homePath()+"/.qupzilla/profiles/"+name);
ui->startProfile->removeItem(ui->startProfile->currentIndex());
}
void Preferences::startProfileIndexChanged(QString index)
{
ui->deleteProfile->setEnabled(m_actProfileName != index);
}
void Preferences::saveSettings()
{
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
@ -500,6 +580,12 @@ void Preferences::saveSettings()
settings.setValue("language",ui->languages->itemData(ui->languages->currentIndex()).toString());
settings.endGroup();
//Profiles
QString homePath = QDir::homePath();
homePath+="/.qupzilla/";
QSettings profileSettings(homePath+"profiles/profiles.ini", QSettings::IniFormat);
profileSettings.setValue("Profiles/startProfile",ui->startProfile->currentText());
m_pluginsList->save();
p_QupZilla->loadSettings();
p_QupZilla->tabWidget()->loadSettings();

View File

@ -65,6 +65,10 @@ private slots:
void cacheValueChanged(int value);
void pageCacheValueChanged(int value);
void createProfile();
void deleteProfile();
void startProfileIndexChanged(QString index);
private:
void updateBgLabel();
Ui::Preferences* ui;
@ -75,6 +79,7 @@ private:
QColor m_menuTextColor;
QString m_homepage;
QString m_newTabUrl;
QString m_actProfileName;
int m_afterLaunch;
int m_onNewTab;
QSize m_bgLabelSize;

View File

@ -331,13 +331,7 @@
</widget>
</item>
<item row="7" column="2">
<widget class="QComboBox" name="startPRofile">
<item>
<property name="text">
<string>default</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="startProfile"/>
</item>
<item row="8" column="2" colspan="2">
<widget class="QFrame" name="frame">
@ -388,6 +382,9 @@
</item>
<item>
<widget class="QPushButton" name="deleteProfile">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -402,7 +399,7 @@
</layout>
</widget>
</item>
<item row="9" column="1">
<item row="10" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -450,6 +447,16 @@
</property>
</spacer>
</item>
<item row="9" column="1" colspan="2">
<widget class="QLabel" name="label_36">
<property name="text">
<string>Note: You cannot delete active profile.</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="stackedWidgetPage2">

View File

@ -495,7 +495,7 @@ void WebView::contextMenuEvent(QContextMenuEvent* event)
menu->addSeparator();
QString selectedText = page()->selectedText();
selectedText.truncate(20);
menu->addAction(QIcon(":icons/used/google.png"), tr("Search ")+selectedText+tr("... on Google"), this, SLOT(searchOnGoogle()))->setData(page()->selectedText());
menu->addAction(QIcon(":icons/menu/google.png"), tr("Search \"%1 ..\" on Google").arg(selectedText), this, SLOT(searchOnGoogle()))->setData(page()->selectedText());
}
if (!menu->isEmpty()) {