Skip to content

Commit

Permalink
[#83945182] Initial commit of QMessageBox notifications for unavailab…
Browse files Browse the repository at this point in the history
…le network path.
  • Loading branch information
evanweaver committed Dec 4, 2014
1 parent 9cb262a commit 392a9e3
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "../model/ComponentData.hpp"
#include "../model/ComponentData_Impl.hpp"

#include <utilities/idd/OS_Building_FieldEnums.hxx>
#include <utilities/idd/OS_Building_FieldEnums.hxx>
#include "../utilities/core/Assert.hpp"

#include <QVBoxLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include "../model/Space.hpp"
#include "../model/Space_Impl.hpp"

#include <utilities/idd/OS_BuildingStory_FieldEnums.hxx>
#include <utilities/idd/OS_Space_FieldEnums.hxx>
#include <utilities/idd/OS_BuildingStory_FieldEnums.hxx>
#include <utilities/idd/OS_Space_FieldEnums.hxx>
#include "../utilities/core/Assert.hpp"

#include <QVBoxLayout>
Expand Down
17 changes: 12 additions & 5 deletions openstudiocore/src/openstudio_lib/OSAppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "../analysisdriver/SimpleProject.hpp"

#include "../utilities/bcl/LocalBCL.hpp"
#include "../utilities/core/PathHelpers.hpp"

#include <QDir>
#include <QMessageBox>
Expand All @@ -42,12 +43,18 @@ namespace openstudio {
OSAppBase::OSAppBase( int & argc, char ** argv, const QSharedPointer<MeasureManager> &t_measureManager )
: QApplication(argc, argv), m_measureManager(t_measureManager)
{
LOG(Debug, "Measures dir: " << openstudio::toString(BCLMeasure::userMeasuresDir()));
if (!QDir().exists(toQString(BCLMeasure::userMeasuresDir()))){
BCLMeasure::setUserMeasuresDir(BCLMeasure::userMeasuresDir());
}
openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();

m_measureManager->updateMeasuresLists();
if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QMessageBox::information(this->mainWidget(), "Network Connection Problem", "Unable to update Measures list.\nYour User Measures Directory appears to be a network directory and is not currently available.\nYou can change your specified User Measures Directory using Preferences->Change My Measures Directory.", QMessageBox::Ok);

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

Wordsmithing:

"Cannot Update User Measures"

"Your My Measures Directory appears to be on a network drive that is not currently available.\nYou can change your specified My Measures Directory using 'Preferences->Change My Measures Directory'."

}
else {
LOG(Debug, "Measures dir: " << openstudio::toString(userMeasuresDir));
if (!QDir().exists(toQString(userMeasuresDir))){
BCLMeasure::setUserMeasuresDir(userMeasuresDir);
}
m_measureManager->updateMeasuresLists();

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

@evanweaver it is probably better to add a default argument to

void MeasureManager::updateMeasuresLists()

void MeasureManager::updateMeasuresLists(bool updateUserMeasures=true)

If network drive is down you should still update the BCL and application measures

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

You should not call BCLMeasure::setUserMeasuresDir(userMeasuresDir); if userMeasuresDir is on an unavailable network drive (you aren't currently but just FYI)

}

m_waitDialog = boost::shared_ptr<WaitDialog>(new WaitDialog("Loading Model","Loading Model"));
}
Expand Down
26 changes: 20 additions & 6 deletions openstudiocore/src/openstudio_lib/OSDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,13 +1525,27 @@ void OSDocument::openMeasuresDlg()
void OSDocument::openChangeMeasuresDirDlg()
{
openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();

QString dirName = QFileDialog::getExistingDirectory( this->mainWindow(),
tr("Select My Measures Directory"),
toQString(userMeasuresDir));


QString dirName("");

if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QString dirName = QFileDialog::getExistingDirectory(this->mainWindow(),
tr("Select My Measures Directory"));
}
else {
QString dirName = QFileDialog::getExistingDirectory(this->mainWindow(),
tr("Select My Measures Directory"),
toQString(userMeasuresDir));
}

userMeasuresDir = toPath(dirName);

if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QMessageBox::information(this->mainWindow(), "Network Connection Problem", "Unable to use new directory.\nYour User Measures Directory appears to be a network directory and is not currently available.\nYou can change your specified User Measures Directory using Preferences->Change My Measures Directory.", QMessageBox::Ok);

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

Wordsmithing:

"Invalid Directory"

"The My Measures Directory you chose appears to be on a network drive that is not currently available.\nYou can change your specified My Measures Directory using 'Preferences->Change My Measures Directory'."

return;
}

if(dirName.length() > 0){
userMeasuresDir = toPath(dirName);
if (BCLMeasure::setUserMeasuresDir(userMeasuresDir)){
OSAppBase::instance()->measureManager().updateMeasuresLists();
}
Expand Down
38 changes: 30 additions & 8 deletions openstudiocore/src/pat_app/PatApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "RunTabController.hpp"
#include "RunView.hpp"
#include "StartupView.hpp"

#include <pat_app/VagrantConfiguration.hxx>

#include "../shared_gui_components/BCLMeasureDialog.hpp"
Expand Down Expand Up @@ -236,11 +237,18 @@ PatApp::PatApp( int & argc, char ** argv, const QSharedPointer<ruleset::RubyUser

mainWindow->show();

if (!QDir().exists(toQString(BCLMeasure::userMeasuresDir()))){
BCLMeasure::setUserMeasuresDir(BCLMeasure::userMeasuresDir());
openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

@evanweaver same as in OS app


if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QMessageBox::information(this->mainWindow, "Network Connection Problem", "Unable to update Measures list.\nYour User Measures Directory appears to be a network directory and is not currently available.\nYou can change your specified User Measures Directory using Preferences->Change My Measures Directory.", QMessageBox::Ok);
}
else {
if (!QDir().exists(toQString(userMeasuresDir))) {
BCLMeasure::setUserMeasuresDir(userMeasuresDir);
}

m_measureManager.updateMeasuresLists();
m_measureManager.updateMeasuresLists();
}

if (!fileName.isEmpty()){
if (openFile(fileName)){
Expand Down Expand Up @@ -1184,12 +1192,26 @@ void PatApp::changeUserMeasuresDir()
{
openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();

QString dirName = QFileDialog::getExistingDirectory( mainWindow,
tr("Select My Measures Directory"),
toQString(userMeasuresDir));
QString dirName("");

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

@evanweaver same as in os app


if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QString dirName = QFileDialog::getExistingDirectory(mainWindow,
tr("Select My Measures Directory"));
}
else {
QString dirName = QFileDialog::getExistingDirectory(mainWindow,
tr("Select My Measures Directory"),
toQString(userMeasuresDir));
}

userMeasuresDir = toPath(dirName);

if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QMessageBox::information(this->mainWindow, "Network Connection Problem", "Unable to use new directory.\nYour User Measures Directory appears to be a network directory and is not currently available.\nYou can change your specified User Measures Directory using Preferences->Change My Measures Directory.", QMessageBox::Ok);
return;
}

if(dirName.length() > 0){
userMeasuresDir = toPath(dirName);
if (BCLMeasure::setUserMeasuresDir(userMeasuresDir)){
emit userMeasuresDirChanged();
}
Expand Down Expand Up @@ -1394,7 +1416,7 @@ void PatApp::attachProject(boost::optional<analysisdriver::SimpleProject> projec

openstudio::analysis::Analysis analysis = m_project->analysis();

// connect signals from the the analysis to this
// connect signals from the analysis to this
bool isConnected = analysis.connect(SIGNAL(changed(ChangeType)), this, SLOT(markAsModified()));
OS_ASSERT(isConnected);

Expand Down
23 changes: 15 additions & 8 deletions openstudiocore/src/shared_gui_components/BCLMeasureDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@

#include "../utilities/core/Assert.hpp"
#include "../utilities/core/StringHelpers.hpp"
#include "../utilities/core/PathHelpers.hpp"

#include <QBoxLayout>
#include <QComboBox>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QComboBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QGroupBox>
#include <QListWidgetItem>
#include <QListWidget>
#include <QTextEdit>

namespace openstudio {

Expand Down Expand Up @@ -122,6 +123,13 @@ QSize BCLMeasureDialog::sizeHint() const

boost::optional<openstudio::BCLMeasure> BCLMeasureDialog::createMeasure()
{
openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();

if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QMessageBox::information(this, "Network Connection Problem", "Unable to create measure.\nYour User Measures Directory appears to be a network directory and is not currently available.\nYou can change the specified directory using Preferences->Change My Measures Directory.", QMessageBox::Ok);

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

Wordsmithing:

"Cannot Create Measure"

"Your My Measures Directory appears to be on a network drive that is not currently available.\nYou can change your specified My Measures Directory using 'Preferences->Change My Measures Directory'."

return boost::optional<openstudio::BCLMeasure>();
}

std::string name = toString(m_nameLineEdit->text());
std::string className = BCLMeasure::makeClassName(name);
std::string lowerClassName = toUnderscoreCase(className);
Expand All @@ -140,7 +148,6 @@ boost::optional<openstudio::BCLMeasure> BCLMeasureDialog::createMeasure()
measureType = MeasureType::ReportingMeasure;
}

openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();
QString folderName = toQString(lowerClassName).append("/");
openstudio::path measureDir = userMeasuresDir / toPath(folderName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
#include "OSListView.hpp"
#include "OSViewSwitcher.hpp"

#include "../openstudio_lib/MainWindow.hpp"
#include "../openstudio_lib/OSAppBase.hpp"
#include "../openstudio_lib/OSDocument.hpp"
#include "../openstudio_lib/OSItem.hpp"

#include "MeasureBadge.hpp"

#include "../utilities/bcl/LocalBCL.hpp"
#include "../utilities/core/Assert.hpp"
#include "../utilities/core/Compare.hpp"
#include "../utilities/core/PathHelpers.hpp"

#include <OpenStudio.hxx>

Expand All @@ -44,6 +48,7 @@
#include <QDrag>
#include <QFile>
#include <QLabel>
#include <QMessageBox>
#include <QMimeData>
#include <QSettings>
#include <QVariant>
Expand Down Expand Up @@ -145,8 +150,14 @@ void LocalLibraryController::showMeasures()
void LocalLibraryController::showMyMeasuresFolder()
{
openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();
QString path = QDir::toNativeSeparators(toQString(userMeasuresDir));
QDesktopServices::openUrl(QUrl("file:///" + path));

if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

@evanweaver I wonder if we should disable all those buttons when offline? Yuck :-(

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

Let's just do this for now

This comment has been minimized.

Copy link
@evanweaver

evanweaver Dec 5, 2014

Author Contributor

I debated that same thing, but I thought of the cloud status button, and left it be.

QMessageBox::information(QApplication::activeWindow(), "Network Connection Problem", "Unable to show My Measures folder.\nYour User Measures Directory appears to be a network directory and is not currently available.\nYou can change your specified User Measures Directory using Preferences->Change My Measures Directory.", QMessageBox::Ok);

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

Wordsmithing:

"Cannot Open Directory"

"Your My Measures Directory appears to be on a network drive that is not currently available.\nYou can change your specified My Measures Directory using 'Preferences->Change My Measures Directory'."

}
else {
QString path = QDir::toNativeSeparators(toQString(userMeasuresDir));
QDesktopServices::openUrl(QUrl("file:///" + path));
}
}

QSharedPointer<LibraryTypeListController> LocalLibraryController::createLibraryListController(const QDomDocument & taxonomy, LocalLibrary::LibrarySource source)
Expand Down Expand Up @@ -685,6 +696,12 @@ void LibraryListController::createItems()

// create items
openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();

if (isNetworkPath(userMeasuresDir) && !isNetworkPathAvailable(userMeasuresDir)) {
QMessageBox::information(QApplication::activeWindow(), "Network Connection Problem", "Unable to create Measure library list.\nYour User Measures Directory appears to be a network directory and is not currently available.\nYou can change your specified User Measures Directory using Preferences->Change My Measures Directory.", QMessageBox::Ok);

This comment has been minimized.

Copy link
@macumber

macumber Dec 5, 2014

Contributor

@evanweaver don't pop a dialog here, just return

return;
}

for( const auto & measure : measures )
{
if( m_taxonomyTag.compare(QString::fromStdString(measure.taxonomyTag()),Qt::CaseInsensitive) == 0 )
Expand Down

4 comments on commit 392a9e3

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

83945182_UserMeasuresDir (macumber) - x86_64-Linux-Ubuntu-14.04-clang-3.5: OK (2157 of 2182 tests passed)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

83945182_UserMeasuresDir (macumber) - x86_64-Linux-Ubuntu-14.04-cppcheck-1.61: OK (0 of 0 tests passed)

Build Badge

@macumber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evanweaver I made a bunch of comments on this page, we can discuss if needed

@macumber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evanweaver Overall nice job!

Please sign in to comment.