[win-nix] portal creation inside the app

This commit is contained in:
Maxim Kadushkin
2016-10-07 16:51:46 +03:00
parent 61e16fc6f3
commit 38b895de5d
12 changed files with 193 additions and 26 deletions

View File

@ -241,7 +241,7 @@ void CAscTabWidget::closeAllEditors()
// }
}
int CAscTabWidget::addPortal(QString url)
int CAscTabWidget::addPortal(QString url, QString name)
{
Q_UNUSED(url);
@ -257,11 +257,9 @@ int CAscTabWidget::addPortal(QString url)
pView->GetCefView()->load((url + "/products/files/?desktop=true").toStdWString());
int id_view = pView->GetCefView()->GetId();
QRegularExpression re(rePortalName);
QRegularExpressionMatch match = re.match(url);
QString portal = match.hasMatch() ? match.captured(1) : url;
QString portal = name.isEmpty() ? Utils::getPortalName(url) : name;
CAscTabData * data = new CAscTabData(portal, cvwtSimple);
CAscTabData * data = new CAscTabData(portal, etPortal);
data->setViewId(id_view);
/* find out the index of the last portal's tab */
@ -447,6 +445,32 @@ int CAscTabWidget::tabIndexByTitle(QString t, CefType vt)
return -1;
}
int CAscTabWidget::tabIndexByTitle(QString t, AscEditorType et)
{
CAscTabData * doc;
for (int i(count()); i-- > 0; ) {
doc = VPtr<CAscTabData>::asPtr(tabBar()->tabData(i));
if (doc && doc->contentType() == et && doc->title() == t)
return i;
}
return -1;
}
int CAscTabWidget::tabIndexByEditorType(AscEditorType et)
{
CAscTabData * doc;
for (int i(count()); i-- > 0; ) {
doc = VPtr<CAscTabData>::asPtr(tabBar()->tabData(i));
if (doc && doc->contentType() == et)
return i;
}
return -1;
}
void CAscTabWidget::openCloudDocument(COpenOptions& opts, bool select)
{
int tabIndex;
@ -491,13 +515,28 @@ int CAscTabWidget::openPortal(const QString& url)
{
int out_val = 1;
QRegularExpression re(rePortalName);
QRegularExpressionMatch match = re.match(url);
QString portal_name = match.hasMatch() ? match.captured(1) : url;
QString portal_name = Utils::getPortalName(url);
int tabIndex = tabIndexByTitle(portal_name, cvwtSimple);
int tabIndex = tabIndexByTitle(portal_name, etPortal);
if (tabIndex < 0) {
tabIndex = addPortal(url), out_val = 2;
tabIndex = addPortal(url, ""), out_val = 2;
}
setCurrentIndex(tabIndex);
return out_val;
}
int CAscTabWidget::newPortal(const QString& url, const QString& name)
{
int out_val = 1;
int tabIndex = tabIndexByEditorType(etNewPortal);
if ( tabIndex < 0 ) {
if ( !((tabIndex = addPortal(url, name)) < 0) ) {
VPtr<CAscTabData>::asPtr(tabBar()->tabData(tabIndex))
->setContentType(etNewPortal);
out_val = 2;
}
}
setCurrentIndex(tabIndex);
@ -506,7 +545,7 @@ int CAscTabWidget::openPortal(const QString& url)
void CAscTabWidget::closePortal(const QString& name, bool editors)
{
closeEditorByIndex(tabIndexByTitle(name, cvwtSimple));
closeEditorByIndex(tabIndexByTitle(name, etPortal));
if (editors) {
wstring wname = name.toStdWString();
@ -573,6 +612,12 @@ void CAscTabWidget::applyDocumentChanging(int id, int type)
((CCefViewEditor *)pView)->SetEditorType(AscEditorType(type));
}
int tabIndex = tabIndexByView(id);
if (!(tabIndex < 0)) {
VPtr<CAscTabData>::asPtr( tabBar()->tabData(tabIndex) )
->setContentType(AscEditorType(type));
}
updateTabIcon(tabIndexByView(id));
}

View File

@ -47,6 +47,8 @@
#define etRecoveryFile AscEditorType(253)
#define etRecentFile AscEditorType(252)
#define etNewFile AscEditorType(251)
#define etPortal AscEditorType(250)
#define etNewPortal AscEditorType(249)
using namespace std;
typedef CefViewWrapperType CefType;
@ -131,7 +133,7 @@ public:
// int addEditor(QString strName, AscEditorType etType = etDocument, std::wstring strUrl = L"");
int addEditor(COpenOptions&);
int addPortal(QString url);
int addPortal(QString url, QString name);
void closeEditorByIndex(int index, bool checkmodified = false);
void closeAllEditors();
void closePortal(const QString&, bool editors = false);
@ -145,6 +147,8 @@ public:
int viewByIndex(int);
int tabIndexByView(QString);
int tabIndexByTitle(QString t, CefType vt);
int tabIndexByTitle(QString t, AscEditorType vt);
int tabIndexByEditorType(AscEditorType vt);
QString titleByIndex(int, bool original = true);
bool modifiedByIndex(int);
int modifiedCount();
@ -173,6 +177,7 @@ public:
void applyDocumentSave(int, bool);
int openPortal(const QString& url);
int newPortal(const QString& url, const QString& name);
public slots:
// void onDocumentNameChanged(int, QString);

View File

@ -38,8 +38,27 @@ CAscTabData::CAscTabData(const QString& t, CefType wt)
, _panel_id(-1)
, _vtype(wt)
, _url()
, _typeContent(etUndefined)
{}
CAscTabData::CAscTabData(const QString& t, AscEditorType ct)
: _title(t), _is_changed(false), _is_closed(false)
, _panel_id(-1)
, _url()
, _typeContent(ct)
{
switch (ct) {
case etDocument:
case etSpreadsheet:
case etPresentation:
_vtype = cvwtEditor;
break;
default:
_vtype = cvwtSimple;
break;
}
}
void CAscTabData::setTitle(const QString& t)
{
_title = t;
@ -103,3 +122,13 @@ bool CAscTabData::isViewType(CefType vt) const
{
return vt == _vtype;
}
AscEditorType CAscTabData::contentType()
{
return _typeContent;
}
void CAscTabData::setContentType(AscEditorType t)
{
_typeContent = t;
}

View File

@ -44,6 +44,7 @@ struct CAscTabData
{
public:
CAscTabData(const QString &, CefType wt = cvwtEditor);
CAscTabData(const QString &, AscEditorType ct);
~CAscTabData() {}
void setTitle(const QString&);
@ -61,6 +62,9 @@ public:
CefType viewType() const;
wstring url() const;
bool isViewType(CefType) const;
AscEditorType contentType();
void setContentType(AscEditorType);
private:
QString _title;
bool _is_changed;
@ -69,6 +73,8 @@ private:
int _panel_id;
CefType _vtype;
wstring _url;
AscEditorType _typeContent;
};
#endif // CASCTABDATA_H

View File

@ -188,6 +188,13 @@ void CCefEventsTransformer::OnEvent(NSEditorApi::CAscMenuEvent *pEvent)
QMetaObject::invokeMethod( pObjParent, "onPortalOpen", Qt::QueuedConnection,
Q_ARG(QString, QString::fromStdWString(pData->get_Param())) );
} else
if ( !(cmd.find(L"portal:new") == std::wstring::npos) ) {
QMetaObject::invokeMethod( pObjParent, "onPortalNew", Qt::QueuedConnection,
Q_ARG(QString, QString::fromStdWString(pData->get_Param())) );
} else
if ( !(cmd.find(L"portal:create") == std::wstring::npos) ) {
QMetaObject::invokeMethod( pObjParent, "onPortalCreate", Qt::QueuedConnection);
} else
if (cmd.compare(L"portal:logout") == 0) {
QMetaObject::invokeMethod( pObjParent, "onPortalLogout", Qt::QueuedConnection,
Q_ARG(QString, QString::fromStdWString(pData->get_Param())) );

View File

@ -1164,6 +1164,59 @@ void CMainPanel::onPortalOpen(QString url)
}
}
void CMainPanel::onPortalNew(QString in)
{
QJsonParseError jerror;
QJsonDocument jdoc = QJsonDocument::fromJson(in.toLatin1(), &jerror);
if(jerror.error == QJsonParseError::NoError) {
QJsonObject objRoot = jdoc.object();
QString _f_name = objRoot["firstName"].toString(),
_l_name = objRoot["lastName"].toString(),
_lang = objRoot["language"].toString(),
_full_name;
if ( _f_name.isEmpty() )
_full_name = _l_name; else
if ( _l_name.isEmpty() )
_full_name = _f_name; else
{
_full_name = _lang.contains("ru", Qt::CaseInsensitive) ?
_l_name + ' ' + _f_name : _f_name + ' ' + _l_name;
}
QString _domain = Utils::getPortalName(objRoot["domain"].toString());
int _tab_index = m_pTabs->tabIndexByEditorType(etNewPortal);
if ( !(_tab_index < 0)) {
int _uid = m_pTabs->viewByIndex(_tab_index);
m_pTabs->applyDocumentChanging(_uid, _domain, _domain);
m_pTabs->applyDocumentChanging(_uid, etPortal);
onTabChanged(m_pTabs->currentIndex());
}
QJsonObject _json_obj;
_json_obj["displayName"] = _full_name;
_json_obj["email"] = objRoot.value("email").toString();
_json_obj["domain"] = _domain;
QTimer::singleShot(20, this, [=]{
cmdMainPage("portal:new", Utils::encodeJson(_json_obj));
});
}
}
void CMainPanel::onPortalCreate()
{
int res = m_pTabs->newPortal(URL_SIGNUP, tr("Sign Up"));
if (res == 2) { RecalculatePlaces(); }
QTimer::singleShot(200, this, [=]{
toggleButtonMain(false);
});
}
void CMainPanel::readSystemUserName(wstring& first, wstring& last)
{
#ifdef Q_OS_WIN

View File

@ -133,6 +133,8 @@ public slots:
void onLocalGetImage(void *);
void onPortalOpen(QString);
void onPortalLogout(QString);
void onPortalNew(QString);
void onPortalCreate();
void onMainPageReady();

View File

@ -54,11 +54,13 @@
#endif
#define WINDOW_NAME "ONLYOFFICE Desktop Editors"
#define URL_SITE "http://www.onlyoffice.com"
#define REG_APP_NAME "DesktopEditors"
#define URL_APPCAST_UPDATES ""
#define APP_MUTEX_NAME "TEAMLAB"
#define URL_SITE "http://www.onlyoffice.com"
#define URL_APPCAST_UPDATES ""
#define URL_SIGNUP "http://192.168.4.111/registration.aspx?desktop=true"
#define WINDOW_TITLE_MIN_WIDTH 400
#define GET_REGISTRY_USER(variable) \

View File

@ -33,8 +33,8 @@
#ifndef VERSION_H
#define VERSION_H
#define VER_FILEVERSION 4,1,1,260
#define VER_FILEVERSION_STR "4.1.1.260\0"
#define VER_FILEVERSION 4,1,2,262
#define VER_FILEVERSION_STR "4.1.2.262\0"
#define VER_PRODUCTVERSION VER_FILEVERSION
#define VER_PRODUCTVERSION_STR "4.1\0"