3 #include <QApplication> 4 #include <QSplashScreen> 6 #include <QCommandLineParser> 7 #include <QDesktopWidget> 8 #include <QFontDatabase> 10 #include <QNetworkAccessManager> 11 #include <QNetworkReply> 12 #include <QJsonDocument> 25 #ifdef COMPILED_WITH_CATKIN 28 #ifdef COMPILED_WITH_AMENT 29 #include <ament_index_cpp/get_package_prefix.hpp> 30 #include <ament_index_cpp/get_package_share_directory.hpp> 33 static QString
VERSION_STRING = QString(
"%1.%2.%3").arg(PJ_MAJOR_VERSION).arg(PJ_MINOR_VERSION).arg(PJ_PATCH_VERSION);
37 QStringList online_version = str.split(
'.');
38 if( online_version.size() != 3 )
42 int major = online_version[0].toInt();
43 int minor = online_version[1].toInt();
44 int patch = online_version[2].toInt();
45 return major * 10000 + minor * 100 + patch;
54 QString answer = reply->readAll();
55 QJsonDocument document = QJsonDocument::fromJson(answer.toUtf8());
56 QJsonObject
data = document.object();
57 QString url = data[
"html_url"].toString();
58 QString
name = data[
"name"].toString();
59 QString tag_name = data[
"tag_name"].toString();
62 QString dont_show = settings.value(
"NewRelease/dontShowThisVersion",
VERSION_STRING).toString();
66 if (online_number > current_number && online_number > dontshow_number)
76 qsrand(
time(
nullptr));
79 const int last_image_num = 60;
80 int n = qrand() % (last_image_num + 2);
81 if (n > last_image_num)
88 int prev_n = settings.value(
"previousFunnySubtitle").toInt();
93 settings.setValue(
"previousFunnySubtitle", n);
94 auto filename = QString(
"://resources/memes/meme_%1.jpg").arg(n, 2, 10, QChar(
'0'));
95 return QPixmap(filename);
98 int main(
int argc,
char* argv[])
100 QApplication app(argc, argv);
102 QCoreApplication::setOrganizationName(
"PlotJuggler");
103 QCoreApplication::setApplicationName(
"PlotJuggler-3");
104 QSettings::setDefaultFormat(QSettings::IniFormat);
108 if( !settings.isWritable() )
110 qDebug() <<
"ERROR: the file [" << settings.fileName() <<
111 "] is not writable. This may happen when you run PlotJuggler with sudo. " 112 "Change the permissions of the file (\"sudo chmod 666 <file_name>\"on linux)";
120 #ifdef COMPILED_WITH_CATKIN 122 QDir ros_plugins_dir( QCoreApplication::applicationDirPath() +
"_ros" );
123 if( !ros_plugins_dir.exists() || ros_plugins_dir.isEmpty() )
125 throw std::runtime_error(
"Missing ros plugins directory");
127 extra_path = ros_plugins_dir.path();
129 #ifdef COMPILED_WITH_AMENT 130 extra_path = QString::fromStdString(ament_index_cpp::get_package_prefix(
"plotjuggler_ros"));
131 extra_path +=
"/lib/plotjuggler_ros";
135 QMessageBox::warning(
nullptr,
"Missing package [plotjuggler-ros]",
136 "If you just upgraded from PlotJuggler 2.x to 3.x , try installing this package:\n\n" 137 "sudo apt install ros-${ROS_DISTRO}-plotjuggler-ros",
138 QMessageBox::Cancel, QMessageBox::Cancel);
142 TransformFactory::registerTransform<FirstDerivative>();
143 TransformFactory::registerTransform<ScaleTransform>();
144 TransformFactory::registerTransform<MovingAverageFilter>();
145 TransformFactory::registerTransform<OutlierRemovalFilter>();
146 TransformFactory::registerTransform<IntegralTransform>();
149 QCommandLineParser parser;
150 parser.setApplicationDescription(
"PlotJuggler: the time series visualization tool that you deserve ");
151 parser.addVersionOption();
152 parser.addHelpOption();
154 QCommandLineOption nosplash_option(QStringList() <<
"n" 156 "Don't display the splashscreen");
157 parser.addOption(nosplash_option);
159 QCommandLineOption test_option(QStringList() <<
"t" 161 "Generate test curves at startup");
162 parser.addOption(test_option);
164 QCommandLineOption loadfile_option(QStringList() <<
"d" 166 "Load a file containing data",
"file");
167 parser.addOption(loadfile_option);
169 QCommandLineOption layout_option(QStringList() <<
"l" 171 "Load a file containing the layout configuration",
"file");
172 parser.addOption(layout_option);
174 QCommandLineOption publish_option(QStringList() <<
"p" 176 "Automatically start publisher when loading the layout file");
177 parser.addOption(publish_option);
179 QCommandLineOption folder_option(QStringList() <<
"extra-plugin-folders",
180 "Add semicolon-separated list of folders where you should look for plugins.");
181 if(!extra_path.isEmpty())
183 folder_option.setDefaultValue( extra_path );
185 parser.addOption(folder_option);
187 QCommandLineOption buffersize_option(QStringList() <<
"buffer_size",
188 QCoreApplication::translate(
"main",
"Change the maximum size of the streaming " 189 "buffer (minimum: 10 default: 60)"),
190 QCoreApplication::translate(
"main",
"seconds"));
191 parser.addOption(buffersize_option);
193 parser.process(*qApp);
195 if (parser.isSet(publish_option) && !parser.isSet(layout_option))
197 std::cerr <<
"Option [ -p / --publish ] is invalid unless [ -l / --layout ] is used too." << std::endl;
201 QIcon app_icon(
"://resources/plotjuggler.svg");
202 QApplication::setWindowIcon(app_icon);
204 QNetworkAccessManager manager;
207 QNetworkRequest request;
208 request.setUrl(QUrl(
"https://api.github.com/repos/facontidavide/PlotJuggler/releases/latest"));
209 manager.get(request);
224 if (!parser.isSet(nosplash_option) && !(parser.isSet(loadfile_option) || parser.isSet(layout_option)))
228 QSplashScreen splash(main_pixmap, Qt::WindowStaysOnTopHint);
229 QDesktopWidget* desktop = QApplication::desktop();
230 const int scrn = desktop->screenNumber(QCursor::pos());
231 const QPoint currentDesktopsCenter = desktop->availableGeometry(scrn).center();
232 splash.move(currentDesktopsCenter - splash.rect().center());
237 auto deadline = QDateTime::currentDateTime().addMSecs(500);
238 while (QDateTime::currentDateTime() < deadline)
245 deadline = QDateTime::currentDateTime().addMSecs(3000);
246 while (QDateTime::currentDateTime() < deadline && !splash.isHidden())
void OpenNewReleaseDialog(QNetworkReply *reply)
QPixmap getFunnySplashscreen()
static QString VERSION_STRING
int GetVersionNumber(QString str)
int main(int argc, char *argv[])