824 {
826 QMessageBox::critical(0, "Error - Empty file name provided",
827 "Empty file name provided.",QMessageBox::Ok,QMessageBox::Ok);
828 return;
829 }
830 QFileInfo fi(filename);
831 if (!fi.exists()) {
832 QMessageBox::critical(0, "Error - file does not exists: "+filename,
833 "File does not exists: <i>"+filename+"</i>",QMessageBox::Ok,QMessageBox::Ok);
834 return;
835 }
836 if (!fi.isReadable()) {
837 QMessageBox::critical(0, "Error - file is not readable: "+filename,
838 "File is not readable: <i>"+filename+"</i>",QMessageBox::Ok,QMessageBox::Ok);
839 return;
840 }
841
842 QFile
file(filename);
843 if (!
file.open(QIODevice::ReadOnly)) {
844 QMessageBox::critical(0, "Error - problems opening file "+filename,
845 "Problems opening file: <i>"+filename+"</i>",QMessageBox::Ok,QMessageBox::Ok);
846 return;
847 }
848
849
851 QStringList pluginfiles;
852 QMap<QString,QMultiMap<QString,ChanState> > tab2channels;
853 QMap<QString,QByteArray> tab2arrangements;
854 QStringList tabs_orded;
855
856 QByteArray byteArray64;
859
860 QByteArray byteArray = qUncompress(QByteArray::fromBase64(byteArray64));
861
862 QBuffer
buffer(&byteArray);
863 buffer.open(QIODevice::ReadOnly);
864 QDataStream in(&buffer);
866 in >> pluginfiles;
867 in >> tab2channels;
868 in >> tab2arrangements;
869 in >> tabs_orded;
870 in >> foot;
872
873 if (
head!=
"This is an automatically generated config file for VP1. [cfg version 003]"
874 ||foot!="This is the end of the automatically generated config file for VP1."
875 ||tab2channels.count()!=tab2arrangements.count()) {
876 QMessageBox::critical(0, "Error - file not in correct format: "+filename,
877 "File not in correct format: <i>"+filename+"</i>",QMessageBox::Ok,QMessageBox::Ok);
878 return;
879 }
880
881 QStringList pf_withproblem;
882 QStringList errormessage;
883
884#ifdef __APPLE__
885 QString sharedlibsuffix_correct = ".dylib";
886 QString sharedlibsuffix_wrong = ".so";
887#else
888 QString sharedlibsuffix_correct = ".so";
889 QString sharedlibsuffix_wrong = ".dylib";
890#endif
891
892 for(QString pf : pluginfiles) {
893 if (
pf.endsWith(sharedlibsuffix_wrong)) {
894 pf.replace(sharedlibsuffix_wrong, sharedlibsuffix_correct);
895 }
896
897 if (!availableplugins.contains(pf)) {
899 errormessage<<
"Could not locate " +
pf;
900 continue;
901 }
902 QString pfabsolute = availableplugins[
pf];
904 if (
m_d->channelmanager->channelsInPluginFile(pfabsolute).empty())
905 err =
m_d->channelmanager->loadPluginFile(pfabsolute);
906 if (!
err.isEmpty()) {
907 pf_withproblem<<pfabsolute;
909 }
910 }
911
912 if (!pf_withproblem.empty()) {
913 assert(pf_withproblem.count()==errormessage.count());
915 for (
int i = 0;
i<pf_withproblem.count();++
i) {
916 tmp += pf_withproblem.value(i)+
": "+errormessage.value(i)+
"\n";
917 }
918 QMessageBox::warning(0, "Warning - could not load all plugins",
919 "Some or more plugins did not load properly:\n\n"+tmp,QMessageBox::Ok,QMessageBox::Ok);
920 }
921
922 QString channelsFailureMsg;
923 QString tabArrangementFailureMsg;
924
925 QString lastaddedtab;
926
927 for (const QString& newtabname_infile : tabs_orded) {
928
929 if (!tab2channels.contains(newtabname_infile)||!tab2arrangements.contains(newtabname_infile)) {
930 QMessageBox::critical(0, "Error - file not in correct format: "+filename,
931 "File not in correct format: <i>"+filename+"</i>",QMessageBox::Ok,QMessageBox::Ok);
932 return;
933 }
934
935
936
937 QMainWindow * existingtab =
m_d->name2tab(newtabname_infile);
938 if (existingtab) {
939 if (
m_d->tab_2_channelwidgets.find(existingtab)==
m_d->tab_2_channelwidgets.end()
940 ||
m_d->tab_2_channelwidgets[existingtab].empty())
942 }
943
944
945
946 if (
m_d->channelwidget_2_dockwidget.empty()
947 &&
m_d->name_2_tab.size()==1
948 &&
m_d->name_2_tab.begin()->first==
"My Tab")
950
953 if (!
m_d->checkTabnameExists(newtabname))
954 return;
955 lastaddedtab=newtabname;
956
957 QMapIterator<QString,ChanState>
it( tab2channels.value(newtabname_infile) );
958
959 while (
it.hasNext()) {
961
962
963 if (!
m_d->channelmanager->baseNameExists(
it.key())) {
964 channelsFailureMsg +=
it.key()+
" (tab "+newtabname+
")"+
"\n";
965 } else {
967 if (cw)
969 else
970 channelsFailureMsg +=
it.key()+
" (tab "+newtabname+
")"+
"\n";
971 }
972 }
973
974
975 assert(
m_d->name_2_tab.find(newtabname)!=
m_d->name_2_tab.end());
976 QMainWindow * tab =
m_d->name_2_tab.find(newtabname)->second;
977 QByteArray state = tab2arrangements.value(newtabname_infile);
978
979 if (!state.isEmpty()) {
980 if (!tab->restoreState(state,0)) {
981 tabArrangementFailureMsg += newtabname+"\n";
982 }
983 }
984 }
985 if (!channelsFailureMsg.isEmpty()) {
986 QMessageBox::warning(0, "Warning - could not start all channels",
987 "Some or more channels were not available to start:\n\n"
988 +channelsFailureMsg,QMessageBox::Ok,QMessageBox::Ok);
989 }
990 if (!tabArrangementFailureMsg.isEmpty()) {
991 QMessageBox::warning(0, "Warning - could not arrange channels in all tabs",
992 "The arrangement of channels could not be properly determined withing the following tabs:\n\n"
993 +tabArrangementFailureMsg,QMessageBox::Ok,QMessageBox::Ok);
994 }
995 if (!lastaddedtab.isEmpty())
997}
bool showTab(const QString &)
QString suggestNewTabName(const QString &oldtabname) const
std::string head(std::string s, const std::string &pattern)
head of a string