BrowserWidget* Core::NewURL (const QUrl& url, bool raise) { if (!Initialized_) return 0; BrowserWidget *widget = new BrowserWidget (); widget->InitShortcuts (); widget->SetUnclosers (Unclosers_); Widgets_.push_back (widget); QString tabTitle = "Poshuku"; if (url.host ().size ()) tabTitle = url.host (); emit addNewTab (tabTitle, widget); ConnectSignals (widget); if (!url.isEmpty ()) widget->SetURL (url); if (raise) emit raiseTab (widget); emit hookTabAdded (Util::DefaultHookProxy_ptr (new Util::DefaultHookProxy), widget, widget->getWebView (), url); return widget; }
void Core::saveSingleSession () { BrowserWidget *source = qobject_cast<BrowserWidget*> (sender ()); if (!source) { qWarning () << Q_FUNC_INFO << "sender is not a BrowserWidget*" << sender (); return; } QSettings settings (QCoreApplication::organizationName (), QCoreApplication::applicationName () + "_Poshuku"); settings.beginWriteArray ("Saved session"); for (int i = 0, size = Widgets_.size (); i < size; ++i) if (Widgets_.at (i) == source) { settings.setArrayIndex (i); settings.setValue ("Title", source->GetView ()->title ()); settings.setValue ("URL", source->GetView ()->url ().toString ()); settings.setValue ("Settings", QVariant::fromValue<BrowserWidgetSettings> (source->GetWidgetSettings ())); break; } // It looks like QSettings determines array size by last used index // no matter what was passed to QSettings::beginWriteArray (). Forcing correct size settings.setArrayIndex (Widgets_.size () - 1); settings.endArray (); settings.sync (); }
void Core::handleNeedToClose () { BrowserWidget *w = dynamic_cast<BrowserWidget*> (sender ()); emit removeTab (w); w->deleteLater (); }
BrowserWidget* Core::NewURL (const QUrl& url, bool raise, const QList<QPair<QByteArray, QVariant>>& props) { if (!Initialized_) return 0; BrowserWidget *widget = new BrowserWidget (); widget->InitShortcuts (); Widgets_.push_back (widget); Q_FOREACH (const auto& pair, props) widget->setProperty (pair.first, pair.second); QString tabTitle = "Poshuku"; if (url.host ().size ()) tabTitle = url.host (); emit addNewTab (tabTitle, widget); ConnectSignals (widget); if (!url.isEmpty ()) widget->SetURL (url); if (raise) emit raiseTab (widget); emit hookTabAdded (Util::DefaultHookProxy_ptr (new Util::DefaultHookProxy), widget, widget->getWebView (), url); return widget; }
IWebWidget* Core::GetWidget () { if (!Initialized_) return 0; BrowserWidget *widget = new BrowserWidget (); widget->Deown (); widget->InitShortcuts (); SetupConnections (widget); return widget; }
QMap<QString, ActionInfo> Poshuku::GetActionInfo () const { BrowserWidget bw; QMap<QString, ActionInfo> result = bw.GetActionInfo (); result ["EAImportXbel_"] = ActionInfo (ImportXbel_->text (), QKeySequence (), ImportXbel_->icon ()); result ["EAExportXbel_"] = ActionInfo (ExportXbel_->text (), QKeySequence (), ExportXbel_->icon ()); result ["EACheckFavorites_"] = ActionInfo (CheckFavorites_->text (), QKeySequence (), CheckFavorites_->icon ()); return result; }
void Core::handleUnclose () { QAction *action = qobject_cast<QAction*> (sender ()); UncloseData ud = action->data ().value<UncloseData> (); BrowserWidget *bw = NewURL (ud.URL_); QDataStream str (ud.History_); str >> *bw->GetView ()->page ()->history (); bw->SetOnLoadScrollPoint (ud.SPoint_); Unclosers_.removeAll (action); action->deleteLater (); }
QWebPage* CustomWebPage::createWindow (QWebPage::WebWindowType type) { Util::DefaultHookProxy_ptr proxy (new Util::DefaultHookProxy); emit hookCreateWindow (proxy, this, type); if (proxy->IsCancelled ()) return qobject_cast<QWebPage*> (proxy->GetReturnValue ().value<QObject*> ()); switch (type) { case QWebPage::WebBrowserWindow: return Core::Instance ().NewURL (QUrl ())->GetView ()->page (); case QWebPage::WebModalDialog: { BrowserWidget *widget = new BrowserWidget (view ()); widget->InitShortcuts (); widget->setWindowFlags (Qt::Dialog); widget->setAttribute (Qt::WA_DeleteOnClose); widget->setWindowModality (Qt::ApplicationModal); connect (widget, SIGNAL (gotEntity (const LeechCraft::Entity&)), &Core::Instance (), SIGNAL (gotEntity (const LeechCraft::Entity&))); connect (widget, SIGNAL (titleChanged (const QString&)), widget, SLOT (setWindowTitle (const QString&))); widget->show (); return widget->GetView ()->page (); } default: qWarning () << Q_FUNC_INFO << "unknown type" << type; return 0; } }