Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/robomongo/core/domain/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "robomongo/core/domain/MongoShell.h"
#include "robomongo/core/domain/MongoCollection.h"
#include "robomongo/core/settings/ConnectionSettings.h"
#include "robomongo/core/settings/SettingsManager.h"
#include "robomongo/core/EventBus.h"
#include "robomongo/core/AppRegistry.h"
#include "robomongo/core/utils/QtUtils.h"
#include "robomongo/core/utils/StdUtils.h"
#include "robomongo/core/utils/Logger.h"
Expand Down Expand Up @@ -98,6 +100,17 @@ namespace Robomongo

MongoShell *App::openShell(ConnectionSettings *connection, const ScriptInfo &scriptInfo)
{
if (!AppRegistry::instance().settingsManager()->useTabbar()) {
for (MongoShellsContainerType::const_iterator it = _shells.begin(); it != _shells.end(); ++it) {
MongoShell *shell = *it;
MongoServer *server = shell->server();
ConnectionSettings *settings = server->connectionRecord();
if (QString::fromStdString(shell->query()) == scriptInfo.script()
&& shell->title() == scriptInfo.title()
&& settings->getFullAddress() == connection->getFullAddress())
return shell;
}
}
MongoServer *server = openServer(connection, false);
MongoShell *shell = new MongoShell(server,scriptInfo);
_shells.push_back(shell);
Expand Down
14 changes: 7 additions & 7 deletions src/robomongo/core/domain/MongoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ namespace Robomongo
return _isConnected;
}

ConnectionSettings *MongoServer::connectionRecord() const
{
return _client->connectionRecord();
ConnectionSettings *MongoServer::connectionRecord() const
{
return _client->connectionRecord();
}

MongoServer::~MongoServer()
{
{
clearDatabases();
delete _client;
_client->stopAndDelete();
}

/**
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace Robomongo
{
const ConnectionInfo &info = event->info();
_isConnected = !event->isError();
if (event->isError()) {
if (event->isError()) {
AppRegistry::instance().bus()->publish(new ConnectionFailedEvent(this, event->error()));
} else if (_visible) {
AppRegistry::instance().bus()->publish(new ConnectionEstablishedEvent(this));
Expand All @@ -139,7 +139,7 @@ namespace Robomongo
MongoDatabase *db = new MongoDatabase(this, name);
addDatabase(db);
}
}
}
_version = info._version;
}

Expand Down
39 changes: 24 additions & 15 deletions src/robomongo/core/mongodb/MongoWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ namespace Robomongo
_isAdmin(true),
_isLoadMongoRcJs(isLoadMongoRcJs),
_batchSize(batchSize),
_timerId(-1)
{
_thread = new QThread(this);
_timerId(-1),
_isQuiting(false)
{
_thread = new QThread();
moveToThread(_thread);
VERIFY(connect( _thread, SIGNAL(started()), this, SLOT(init()) ));
VERIFY(connect( _thread, SIGNAL(finished()), _thread, SLOT(deleteLater()) ));
VERIFY(connect( _thread, SIGNAL(finished()), this, SLOT(deleteLater()) ));
_thread->start();
}

Expand Down Expand Up @@ -66,7 +69,7 @@ namespace Robomongo
}

void MongoWorker::init()
{
{
try {
_scriptEngine = new ScriptEngine(_connection);
_scriptEngine->init(_isLoadMongoRcJs);
Expand All @@ -81,14 +84,16 @@ namespace Robomongo

MongoWorker::~MongoWorker()
{
killTimer(_timerId);
delete _dbclient;
delete _connection;
_thread->quit();
if (!_thread->wait(2000))
_thread->terminate();

delete _scriptEngine;
delete _thread;
}

void MongoWorker::stopAndDelete()
{
_isQuiting = true;
_thread->quit();
}

/**
Expand Down Expand Up @@ -139,7 +144,7 @@ namespace Robomongo
}

MongoWorker::DatabasesContainerType MongoWorker::getDatabaseNamesSafe()
{
{
DatabasesContainerType result;
std::string authBase = getAuthBase();
if (!_isAdmin && !authBase.empty()) {
Expand Down Expand Up @@ -168,7 +173,7 @@ namespace Robomongo
// If user not an admin - he doesn't have access to mongodb 'listDatabases' command
// Non admin user has access only to the single database he specified while performing auth.
std::vector<std::string> dbNames = getDatabaseNamesSafe();

if(dbNames.size()){
reply(event->sender(), new LoadDatabaseNamesResponse(this, dbNames));
}else{
Expand Down Expand Up @@ -250,7 +255,7 @@ namespace Robomongo
} catch(const mongo::DBException &ex) {
reply(event->sender(), new DeleteCollectionIndexResponse(this, event->collection(), std::string() ));
LOG_MSG(ex.what(), mongo::LL_ERROR);
}
}
}

void MongoWorker::handle(EditIndexRequest *event)
Expand All @@ -265,7 +270,7 @@ namespace Robomongo
} catch(const mongo::DBException &ex) {
reply(event->sender(), new LoadCollectionIndexesResponse(this, std::vector<EnsureIndexInfo>()));
LOG_MSG(ex.what(), mongo::LL_ERROR);
}
}
}

void MongoWorker::handle(LoadFunctionsRequest *event)
Expand Down Expand Up @@ -530,14 +535,18 @@ namespace Robomongo
*/
void MongoWorker::send(Event *event)
{
AppRegistry::instance().bus()->send(this, event);
if (!_isQuiting) {
AppRegistry::instance().bus()->send(this, event);
}
}

/**
* @brief Send reply event to object 'receiver'
*/
void MongoWorker::reply(QObject *receiver, Event *event)
{
AppRegistry::instance().bus()->send(receiver, event);
if (!_isQuiting) {
AppRegistry::instance().bus()->send(receiver, event);
}
}
}
5 changes: 4 additions & 1 deletion src/robomongo/core/mongodb/MongoWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace Robomongo
ConnectionSettings *connectionRecord() const {return _connection;}
~MongoWorker();
enum{pingTimeMs = 60*1000};


void stopAndDelete();

protected Q_SLOTS: // handlers:
void init();
/**
Expand Down Expand Up @@ -145,6 +147,7 @@ namespace Robomongo
const bool _isLoadMongoRcJs;
const int _batchSize;
int _timerId;
QAtomicInteger<bool> _isQuiting;

ConnectionSettings *_connection;
};
Expand Down
16 changes: 15 additions & 1 deletion src/robomongo/core/settings/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ namespace Robomongo
it = _toolbars.find("logs");
if (_toolbars.end() == it)
_toolbars["logs"] = false;

if (map.contains("useTabbar")) {
_useTabbar = map.value("useTabbar").toBool();
} else {
_useTabbar = true; // Default
}
}

/**
Expand Down Expand Up @@ -258,6 +264,8 @@ namespace Robomongo

map.insert("toolbars", _toolbars);

map.insert("useTabbar", _useTabbar);

return map;
}

Expand Down Expand Up @@ -291,10 +299,16 @@ namespace Robomongo
_textFontFamily = fontFamily;
}

void SettingsManager::setTextFontPointSize(int pointSize) {
void SettingsManager::setTextFontPointSize(int pointSize)
{
_textFontPointSize = pointSize > 0 ? pointSize : -1;
}

void SettingsManager::setUseTabbar(bool usesTabbar)
{
_useTabbar = usesTabbar;
}

void SettingsManager::reorderConnections(const ConnectionSettingsContainerType &connections)
{
_connections = connections;
Expand Down
4 changes: 4 additions & 0 deletions src/robomongo/core/settings/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ namespace Robomongo
int textFontPointSize() const { return _textFontPointSize; }
void setTextFontPointSize(int pointSize);

bool useTabbar() const { return _useTabbar; }
void setUseTabbar(bool useTabbar);


private:

Expand Down Expand Up @@ -144,6 +147,7 @@ namespace Robomongo
QString _currentStyle;
QString _textFontFamily;
int _textFontPointSize;
bool _useTabbar;
/**
* @brief List of connections
*/
Expand Down
Loading