int ESP8266::connectWifi(char *ssid, char *password) { strcpy(_ssid, ssid); strcpy(_password, password); // set the access point value and connect wifi.print(F("AT+CWJAP=\"")); wifi.print(ssid); wifi.print(F("\",\"")); wifi.print(password); wifi.println(F("\"")); delay(100); if(!searchResults("OK", 30000, _debugLevel)) { return WIFI_ERR_CONNECT; } // enable multi-connection mode if (!setLinkMode(1)) { return WIFI_ERR_LINK; } // get the IP assigned by DHCP getIP(); // get the broadcast address (assumes class c w/ .255) getBroadcast(); return WIFI_ERR_NONE; }
bool ESP8266::setLinkMode(int mode) { wifi.print(F("AT+CIPMUX=")); wifi.println(mode); delay(500); if(!searchResults("OK", 1000, _debugLevel)){ return false; } return true; }
int ESP8266::initializeWifi(DataCallback dcb, ConnectCallback ccb) { if (dcb) { _dcb = dcb; } if (ccb) { _ccb = ccb; } wifi.begin(_baudrate); wifi.setTimeout(5000); delay(500); clearResults(); // check for presence of wifi module wifi.println(F("AT")); delay(500); if(!searchResults("OK", 1000, _debugLevel)) { return WIFI_ERR_AT; } //delay(500); // reset WiFi module wifi.println(F("AT+RST")); delay(500); if(!searchResults("ready", 5000, _debugLevel)) { return WIFI_ERR_RESET; } delay(500); // set the connectivity mode 1=sta, 2=ap, 3=sta+ap wifi.print(F("AT+CWMODE=")); wifi.println(_mode); //delay(500); clearResults(); return WIFI_ERR_NONE; }
bool ESP8266::startUDPChannel(int chan, char *address, int port) { wifi.print(F("AT+CIPSTART=")); wifi.print(chan); wifi.print(F(",\"UDP\",\"")); wifi.print(address); wifi.print("\","); wifi.println(port); if(!searchResults("OK", 500, _debugLevel)) { return false; } return true; }
void SciDoc::highlightSearchResults() { Juff::SearchResults* results = searchResults(); if ( results == NULL ) return; // keep cursor position or selection for edit1 bool ed1_hasSelection = int_->edit1_->hasSelectedText(); int ed1_r1, ed1_c1, ed1_r2, ed1_c2; int ed1_scrollPos = int_->edit1_->verticalScrollBar()->value(); if ( ed1_hasSelection ) { int_->edit1_->getSelection(&ed1_r1, &ed1_c1, &ed1_r2, &ed1_c2); } else { int_->edit1_->getCursorPosition(&ed1_r1, &ed1_c1); } // keep cursor position or selection for edit2 bool ed2_hasSelection = int_->edit2_->hasSelectedText(); int ed2_r1, ed2_c1, ed2_r2, ed2_c2; int ed2_scrollPos = int_->edit2_->verticalScrollBar()->value(); if ( ed2_hasSelection ) { int_->edit2_->getSelection(&ed2_r1, &ed2_c1, &ed2_r2, &ed2_c2); } else { int_->edit2_->getCursorPosition(&ed2_r1, &ed2_c1); } int count = results->count(); for ( int i = 0; i < count; i++ ) { const Juff::SearchOccurence& occ = results->occurence(i); int_->edit1_->highlight(JuffScintilla::HLSearch, occ.startRow, occ.startCol, occ.endRow, occ.endCol); int_->edit2_->highlight(JuffScintilla::HLSearch, occ.startRow, occ.startCol, occ.endRow, occ.endCol); } // restore cursor position or selection for edit1 if ( ed1_hasSelection ) { int_->edit1_->setSelection(ed1_r1, ed1_c1, ed1_r2, ed1_c2); } else { int_->edit1_->setCursorPosition(ed1_r1, ed1_c1); } int_->edit1_->verticalScrollBar()->setValue(ed1_scrollPos); // restore cursor position or selection for edit2 if ( ed2_hasSelection ) { int_->edit2_->setSelection(ed2_r1, ed2_c1, ed2_r2, ed2_c2); } else { int_->edit2_->setCursorPosition(ed2_r1, ed2_c1); } int_->edit2_->verticalScrollBar()->setValue(ed2_scrollPos); }
bool ESP8266::startServer(int port, long timeout) { // cache the port number for the beacon _port = port; wifi.print(F("AT+CIPSERVER=")); wifi.print(SVR_CHAN); wifi.print(F(",")); wifi.println(_port); if(!searchResults("OK", 500, _debugLevel)){ return false; } // send AT command wifi.print(F("AT+CIPSTO=")); wifi.println(timeout); if(!searchResults("OK", 500, _debugLevel)) { return false; } _connectMode = CONNECT_MODE_SERVER; return true; }
bool ESP8266::startClient(char *ip, int port, long timeout) { wifi.print(F("AT+CIPSTART=")); wifi.print(CLI_CHAN); wifi.print(F(",\"TCP\",\"")); wifi.print(ip); wifi.print("\","); wifi.println(port); delay(100); if(!searchResults("OK", timeout, _debugLevel)) { return false; } _connectMode = CONNECT_MODE_CLIENT; return true; }
bool ESP8266::sendData(int chan, char *data) { // start send wifi.print(F("AT+CIPSEND=")); wifi.print(chan); wifi.print(","); wifi.println(strlen(data)); // send the data wifi.println(data); delay(50); // to debug only searchResults("OK", 500, _debugLevel); return true; }
CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent, bool rangemode) : GcWindow(parent), _dateRange("{00000000-0000-0000-0000-000000000001}"), home(home), mainWindow(parent), currentRide(NULL), rangemode(rangemode), stale(true), useCustom(false) { setInstanceName("Critical Power Window"); // main plot area QVBoxLayout *vlayout = new QVBoxLayout; cpintPlot = new CpintPlot(mainWindow, home.path(), mainWindow->zones()); vlayout->addWidget(cpintPlot); setLayout(vlayout); // controls QWidget *c = new QWidget; QFormLayout *cl = new QFormLayout(c); setControls(c); #ifdef GC_HAVE_LUCENE // searchbox searchBox = new SearchFilterBox(this, parent); connect(searchBox, SIGNAL(searchClear()), cpintPlot, SLOT(clearFilter())); connect(searchBox, SIGNAL(searchResults(QStringList)), cpintPlot, SLOT(setFilter(QStringList))); connect(searchBox, SIGNAL(searchClear()), this, SLOT(filterChanged())); connect(searchBox, SIGNAL(searchResults(QStringList)), this, SLOT(filterChanged())); cl->addRow(new QLabel(tr("Filter")), searchBox); cl->addWidget(new QLabel("")); //spacing #endif // picker details QLabel *cpintTimeLabel = new QLabel(tr("Duration:"), this); cpintTimeValue = new QLineEdit("0 s"); QLabel *cpintTodayLabel = new QLabel(tr("Today:"), this); cpintTodayValue = new QLabel(tr("no data")); QLabel *cpintAllLabel = new QLabel(tr("Best:"), this); cpintAllValue = new QLabel(tr("no data")); QLabel *cpintCPLabel = new QLabel(tr("CP Curve:"), this); cpintCPValue = new QLabel(tr("no data")); //QFontMetrics metrics(QApplication::font()); //int width = metrics.width("8888 watts (88/88/8888)") + 10; //cpintAllValue->setFixedWidth(width); //cpintCPValue->setFixedWidth(width); // so lines up nicely cpintTimeValue->setReadOnly(false); //cpintTodayValue->setReadOnly(true); //cpintAllValue->setReadOnly(true); //cpintCPValue->setReadOnly(true); QFont font = cpintTimeValue->font(); font.setPointSize(font.pointSize()); cpintTodayValue->setFont(font); cpintAllValue->setFont(font); cpintCPValue->setFont(font); cl->addRow(cpintTimeLabel, cpintTimeValue); cl->addRow(cpintTodayLabel, cpintTodayValue); cl->addRow(cpintAllLabel, cpintAllValue); cl->addRow(cpintCPLabel, cpintCPValue); cl->addWidget(new QLabel("")); //spacing // tools /properties seriesCombo = new QComboBox(this); addSeries(); cComboSeason = new QComboBox(this); seasons = parent->seasons; resetSeasons(); QLabel *label = new QLabel(tr("Date range")); QLabel *label2 = new QLabel(tr("Date range")); if (rangemode) { cComboSeason->hide(); label2->hide(); } cpintSetCPButton = new QPushButton(tr("&Save CP value"), this); cpintSetCPButton->setEnabled(false); cl->addRow(label2, cComboSeason); dateSetting = new DateSettingsEdit(this); cl->addRow(label, dateSetting); if (rangemode == false) { dateSetting->hide(); label->hide(); } cl->addWidget(new QLabel("")); //spacing cl->addRow(new QLabel(tr("Data series")), seriesCombo); cl->addRow(new QLabel(""), cpintSetCPButton); picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPicker::VLineRubberBand, QwtPicker::AlwaysOff, cpintPlot->canvas()); picker->setStateMachine(new QwtPickerDragPointMachine); picker->setRubberBandPen(GColor(CPLOTTRACKER)); connect(picker, SIGNAL(moved(const QPoint &)), SLOT(pickerMoved(const QPoint &))); connect(cpintTimeValue, SIGNAL(editingFinished()), this, SLOT(cpintTimeValueEntered())); connect(cpintSetCPButton, SIGNAL(clicked()), this, SLOT(cpintSetCPButtonClicked())); if (rangemode) { connect(this, SIGNAL(dateRangeChanged(DateRange)), SLOT(dateRangeChanged(DateRange))); } else { connect(cComboSeason, SIGNAL(currentIndexChanged(int)), this, SLOT(seasonSelected(int))); } connect(seriesCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setSeries(int))); //connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(rideSelected())); connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); connect(mainWindow, SIGNAL(configChanged()), cpintPlot, SLOT(configChanged())); // redraw on config change -- this seems the simplest approach connect(mainWindow, SIGNAL(configChanged()), this, SLOT(rideSelected())); connect(mainWindow, SIGNAL(rideAdded(RideItem*)), this, SLOT(newRideAdded(RideItem*))); connect(mainWindow, SIGNAL(rideDeleted(RideItem*)), this, SLOT(newRideAdded(RideItem*))); connect(seasons, SIGNAL(seasonsChanged()), this, SLOT(resetSeasons())); connect(dateSetting, SIGNAL(useCustomRange(DateRange)), this, SLOT(useCustomRange(DateRange))); connect(dateSetting, SIGNAL(useThruToday()), this, SLOT(useThruToday())); connect(dateSetting, SIGNAL(useStandardRange()), this, SLOT(useStandardRange())); }
// // Constructor // HistogramWindow::HistogramWindow(Context *context, bool rangemode) : GcChartWindow(context), context(context), stale(true), source(NULL), active(false), bactive(false), rangemode(rangemode), useCustom(false), useToToday(false), precision(99) { QWidget *c = new QWidget; c->setContentsMargins(0,0,0,0); QFormLayout *cl = new QFormLayout(c); cl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); cl->setSpacing(5); setControls(c); // // reveal controls widget // // reveal controls rWidth = new QLabel(tr("Bin Width")); rBinEdit = new QLineEdit(); rBinEdit->setFixedWidth(40); rBinSlider = new QSlider(Qt::Horizontal); rBinSlider->setTickPosition(QSlider::TicksBelow); rBinSlider->setTickInterval(10); rBinSlider->setMinimum(1); rBinSlider->setMaximum(100); rShade = new QCheckBox(tr("Shade zones")); rZones = new QCheckBox(tr("Show in zones")); // layout reveal controls QHBoxLayout *r = new QHBoxLayout; r->setContentsMargins(0,0,0,0); r->addStretch(); r->addWidget(rWidth); r->addWidget(rBinEdit); r->addWidget(rBinSlider); QVBoxLayout *v = new QVBoxLayout; v->addWidget(rShade); v->addWidget(rZones); r->addSpacing(20); r->addLayout(v); r->addStretch(); setRevealLayout(r); // plot QVBoxLayout *vlayout = new QVBoxLayout; vlayout->setSpacing(10); powerHist = new PowerHist(context); vlayout->addWidget(powerHist); setChartLayout(vlayout); #ifdef GC_HAVE_LUCENE // search filter box isfiltered = false; searchBox = new SearchFilterBox(this, context); connect(searchBox, SIGNAL(searchClear()), this, SLOT(clearFilter())); connect(searchBox, SIGNAL(searchResults(QStringList)), this, SLOT(setFilter(QStringList))); if (!rangemode) searchBox->hide(); else { cl->addRow(new QLabel(tr("Filter")), searchBox); cl->addWidget(new QLabel("")); } #endif // date selection dateSetting = new DateSettingsEdit(this); if (rangemode) { cl->addRow(new QLabel(tr("Date Range")), dateSetting); cl->addWidget(new QLabel("")); // spacing // default to data series! data = new QRadioButton(tr("Ride Data Samples")); metric = new QRadioButton(tr("Ride Metrics")); data->setChecked(true); metric->setChecked(false); QHBoxLayout *radios = new QHBoxLayout; radios->addWidget(data); radios->addWidget(metric); cl->addRow(new QLabel(tr("Plot")), radios); connect(data, SIGNAL(toggled(bool)), this, SLOT(dataToggled(bool))); connect(metric, SIGNAL(toggled(bool)), this, SLOT(metricToggled(bool))); } // data series seriesCombo = new QComboBox(); addSeries(); if (rangemode) comboLabel = new QLabel(""); else comboLabel = new QLabel(tr("Data Series")); cl->addRow(comboLabel, seriesCombo); if (rangemode) { // TOTAL METRIC totalMetricTree = new QTreeWidget; #ifdef Q_OS_MAC totalMetricTree->setAttribute(Qt::WA_MacShowFocusRect, 0); #endif totalMetricTree->setColumnCount(2); totalMetricTree->setColumnHidden(1, true); totalMetricTree->setSelectionMode(QAbstractItemView::SingleSelection); totalMetricTree->header()->hide(); //totalMetricTree->setFrameStyle(QFrame::NoFrame); //totalMetricTree->setAlternatingRowColors (true); totalMetricTree->setIndentation(5); totalMetricTree->setContextMenuPolicy(Qt::CustomContextMenu); // ALL METRIC distMetricTree = new QTreeWidget; #ifdef Q_OS_MAC distMetricTree->setAttribute(Qt::WA_MacShowFocusRect, 0); #endif distMetricTree->setColumnCount(2); distMetricTree->setColumnHidden(1, true); distMetricTree->setSelectionMode(QAbstractItemView::SingleSelection); distMetricTree->header()->hide(); //distMetricTree->setFrameStyle(QFrame::NoFrame); distMetricTree->setIndentation(5); distMetricTree->setContextMenuPolicy(Qt::CustomContextMenu); // add them all const RideMetricFactory &factory = RideMetricFactory::instance(); for (int i = 0; i < factory.metricCount(); ++i) { const RideMetric *m = factory.rideMetric(factory.metricName(i)); QTextEdit processHTML(m->name()); // process html encoding of(TM) QString processed = processHTML.toPlainText(); QTreeWidgetItem *add; add = new QTreeWidgetItem(distMetricTree->invisibleRootItem()); add->setText(0, processed); add->setText(1, m->symbol()); // we only want totalising metrics if (m->type() != RideMetric::Total) continue; add = new QTreeWidgetItem(totalMetricTree->invisibleRootItem()); add->setText(0, processed); add->setText(1, m->symbol()); } QHBoxLayout *labels = new QHBoxLayout; metricLabel1 = new QLabel(tr("Total (x-axis)")); labels->addWidget(metricLabel1); metricLabel1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); metricLabel2 = new QLabel(tr("Distribution (y-axis)")); metricLabel2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); labels->addWidget(metricLabel2); cl->addRow((blankLabel1=new QLabel("")), labels); QHBoxLayout *trees = new QHBoxLayout; trees->addWidget(totalMetricTree); trees->addWidget(distMetricTree); cl->addRow((blankLabel2 = new QLabel("")), trees); colorButton = new ColorButton(this, "Color", QColor(Qt::blue)); colorLabel = new QLabel(tr("Color")); connect(colorButton, SIGNAL(colorChosen(QColor)), this, SLOT(updateChart())); cl->addRow(colorLabel, colorButton); // by default select number of rides by duration // which are the metrics workout_time and ride_count selectTotal("ride_count"); selectMetric("workout_time"); } showSumY = new QComboBox(); showSumY->addItem(tr("Absolute Time")); showSumY->addItem(tr("Percentage Time")); showLabel = new QLabel(tr("Show")); cl->addRow(showLabel, showSumY); showLnY = new QCheckBox; showLnY->setText(tr("Log Y")); cl->addRow(blankLabel3 = new QLabel(""), showLnY); showZeroes = new QCheckBox; showZeroes->setText(tr("With zeros")); cl->addRow(blankLabel4 = new QLabel(""), showZeroes); shadeZones = new QCheckBox; shadeZones->setText(tr("Shade zones")); cl->addRow(blankLabel5 = new QLabel(""), shadeZones); showInZones = new QCheckBox; showInZones->setText(tr("Show in zones")); cl->addRow(blankLabel6 = new QLabel(""), showInZones); // bin width QHBoxLayout *binWidthLayout = new QHBoxLayout; QLabel *binWidthLabel = new QLabel(tr("Bin width"), this); binWidthLineEdit = new QLineEdit(this); binWidthLineEdit->setFixedWidth(40); binWidthLayout->addWidget(binWidthLineEdit); binWidthSlider = new QSlider(Qt::Horizontal); binWidthSlider->setTickPosition(QSlider::TicksBelow); binWidthSlider->setTickInterval(1); binWidthSlider->setMinimum(1); binWidthSlider->setMaximum(100); binWidthLayout->addWidget(binWidthSlider); cl->addRow(binWidthLabel, binWidthLayout); // sort out default values setBinEditors(); showLnY->setChecked(powerHist->islnY()); showZeroes->setChecked(powerHist->withZeros()); shadeZones->setChecked(powerHist->shade); binWidthSlider->setValue(powerHist->binWidth()); rBinSlider->setValue(powerHist->binWidth()); rShade->setChecked(powerHist->shade); // fixup series selected by default seriesChanged(); // hide/show according to default mode switchMode(); // does nothing if not in rangemode // set the defaults etc updateChart(); // the bin slider/input update each other // only the input box triggers an update to the chart connect(binWidthSlider, SIGNAL(valueChanged(int)), this, SLOT(setBinWidthFromSlider())); connect(binWidthLineEdit, SIGNAL(editingFinished()), this, SLOT(setBinWidthFromLineEdit())); connect(rBinSlider, SIGNAL(valueChanged(int)), this, SLOT(setrBinWidthFromSlider())); connect(rBinEdit, SIGNAL(editingFinished()), this, SLOT(setrBinWidthFromLineEdit())); connect(rZones, SIGNAL(stateChanged(int)), this, SLOT(setZoned(int))); connect(rShade, SIGNAL(stateChanged(int)), this, SLOT(setShade(int))); // when season changes we need to retrieve data from the cache then update the chart if (rangemode) { connect(this, SIGNAL(dateRangeChanged(DateRange)), this, SLOT(dateRangeChanged(DateRange))); connect(dateSetting, SIGNAL(useCustomRange(DateRange)), this, SLOT(useCustomRange(DateRange))); connect(dateSetting, SIGNAL(useThruToday()), this, SLOT(useThruToday())); connect(dateSetting, SIGNAL(useStandardRange()), this, SLOT(useStandardRange())); connect(distMetricTree, SIGNAL(itemSelectionChanged()), this, SLOT(treeSelectionChanged())); connect(totalMetricTree, SIGNAL(itemSelectionChanged()), this, SLOT(treeSelectionChanged())); lagger = new QTimer; lagger->setSingleShot(true); connect(lagger, SIGNAL(timeout()), this, SLOT(treeSelectionTimeout())); } else { dateSetting->hide(); connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); connect(context, SIGNAL(intervalSelected()), this, SLOT(intervalSelected())); } // if any of the controls change we pass the chart everything connect(showLnY, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(showZeroes, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(seriesCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(seriesChanged())); connect(showInZones, SIGNAL(stateChanged(int)), this, SLOT(setZoned(int))); connect(showInZones, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(shadeZones, SIGNAL(stateChanged(int)), this, SLOT(setShade(int))); connect(shadeZones, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(showSumY, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChart())); connect(context->athlete, SIGNAL(zonesChanged()), this, SLOT(zonesChanged())); connect(context, SIGNAL(configChanged()), powerHist, SLOT(configChanged())); connect(context, SIGNAL(rideAdded(RideItem*)), this, SLOT(rideAddorRemove(RideItem*))); connect(context, SIGNAL(rideDeleted(RideItem*)), this, SLOT(rideAddorRemove(RideItem*))); connect(context, SIGNAL(filterChanged()), this, SLOT(forceReplot())); connect(context, SIGNAL(homeFilterChanged()), this, SLOT(forceReplot())); }
MainWindow::MainWindow(const QDir &home) { /*---------------------------------------------------------------------- * Bootstrap *--------------------------------------------------------------------*/ setAttribute(Qt::WA_DeleteOnClose); mainwindows.append(this); // add us to the list of open windows context = new Context(this); context->athlete = new Athlete(context, home); setInstanceName(context->athlete->cyclist); setWindowIcon(QIcon(":images/gc.png")); setWindowTitle(context->athlete->home.dirName()); setContentsMargins(0,0,0,0); setAcceptDrops(true); GCColor *GCColorSet = new GCColor(context); // get/keep colorset GCColorSet->colorSet(); // shut up the compiler #ifdef Q_OS_MAC // get an autorelease pool setup static CocoaInitializer cocoaInitializer; #endif #ifdef GC_HAVE_WFAPI WFApi *w = WFApi::getInstance(); // ensure created on main thread w->apiVersion();//shutup compiler #endif Library::initialise(context->athlete->home); QNetworkProxyQuery npq(QUrl("http://www.google.com")); QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq); if (listOfProxies.count() > 0) { QNetworkProxy::setApplicationProxy(listOfProxies.first()); } if (desktop == NULL) desktop = QApplication::desktop(); static const QIcon hideIcon(":images/toolbar/main/hideside.png"); static const QIcon rhideIcon(":images/toolbar/main/hiderside.png"); static const QIcon showIcon(":images/toolbar/main/showside.png"); static const QIcon rshowIcon(":images/toolbar/main/showrside.png"); static const QIcon tabIcon(":images/toolbar/main/tab.png"); static const QIcon tileIcon(":images/toolbar/main/tile.png"); static const QIcon fullIcon(":images/toolbar/main/togglefull.png"); #if (defined Q_OS_MAC) && (defined GC_HAVE_LION) fullScreen = new LionFullScreen(context); #endif #ifndef Q_OS_MAC fullScreen = new QTFullScreen(context); #endif // if no workout directory is configured, default to the // top level GoldenCheetah directory if (appsettings->value(NULL, GC_WORKOUTDIR).toString() == "") appsettings->setValue(GC_WORKOUTDIR, QFileInfo(context->athlete->home.absolutePath() + "/../").absolutePath()); /*---------------------------------------------------------------------- * GUI setup *--------------------------------------------------------------------*/ // need to restore geometry before setUnifiedToolBar.. on Mac appsettings->setValue(GC_SETTINGS_LAST, context->athlete->home.dirName()); QVariant geom = appsettings->value(this, GC_SETTINGS_MAIN_GEOM); if (geom == QVariant()) { // first run -- lets set some sensible defaults... // lets put it in the middle of screen 1 QRect size = desktop->availableGeometry(); struct SizeSettings app = GCColor::defaultSizes(size.height(), size.width()); // center on the available screen (minus toolbar/sidebar) move((size.width()-size.x())/2 - app.width/2, (size.height()-size.y())/2 - app.height/2); // set to the right default resize(app.width, app.height); // set all the default font sizes appsettings->setValue(GC_FONT_DEFAULT_SIZE, app.defaultFont); appsettings->setValue(GC_FONT_TITLES_SIZE, app.titleFont); appsettings->setValue(GC_FONT_CHARTMARKERS_SIZE, app.markerFont); appsettings->setValue(GC_FONT_CHARTLABELS_SIZE, app.labelFont); appsettings->setValue(GC_FONT_CALENDAR_SIZE, app.calendarFont); appsettings->setValue(GC_FONT_POPUP_SIZE, app.popupFont); // set the default fontsize QFont font; font.setPointSize(app.defaultFont); QApplication::setFont(font); } else { QRect size = desktop->availableGeometry(); // ensure saved geometry isn't greater than current screen size if ((geom.toRect().height() >= size.height()) || (geom.toRect().width() >= size.width())) setGeometry(size.x()+30,size.y()+30,size.width()-60,size.height()-60); else setGeometry(geom.toRect()); } /*---------------------------------------------------------------------- * Mac Toolbar *--------------------------------------------------------------------*/ #ifdef Q_OS_MAC setUnifiedTitleAndToolBarOnMac(true); head = addToolBar(context->athlete->cyclist); head->setContentsMargins(0,0,0,0); // widgets QWidget *macAnalButtons = new QWidget(this); macAnalButtons->setContentsMargins(0,0,20,0); // lhs buttons QHBoxLayout *lb = new QHBoxLayout(macAnalButtons); lb->setContentsMargins(0,0,0,0); lb->setSpacing(0); import = new QtMacButton(this, QtMacButton::TexturedRounded); QPixmap *importImg = new QPixmap(":images/mac/download.png"); import->setImage(importImg); import->setToolTip("Download"); lb->addWidget(import); lb->addWidget(new Spacer(this)); compose = new QtMacButton(this, QtMacButton::TexturedRounded); QPixmap *composeImg = new QPixmap(":images/mac/compose.png"); compose->setImage(composeImg); compose->setToolTip("Create"); lb->addWidget(compose); // connect to actions connect(import, SIGNAL(clicked(bool)), this, SLOT(downloadRide())); connect(compose, SIGNAL(clicked(bool)), this, SLOT(manualRide())); lb->addWidget(new Spacer(this)); // activity actions .. peaks, split, delete QWidget *acts = new QWidget(this); acts->setContentsMargins(0,0,0,0); QHBoxLayout *pp = new QHBoxLayout(acts); pp->setContentsMargins(0,0,0,0); pp->setContentsMargins(0,0,0,0); pp->setSpacing(5); sidebar = new QtMacButton(this, QtMacButton::TexturedRounded); QPixmap *sidebarImg = new QPixmap(":images/mac/sidebar.png"); sidebar->setImage(sidebarImg); sidebar->setMinimumSize(25, 25); sidebar->setMaximumSize(25, 25); sidebar->setToolTip("Sidebar"); sidebar->setSelected(true); // assume always start up with sidebar selected actbuttons = new QtMacSegmentedButton(3, acts); actbuttons->setWidth(115); actbuttons->setNoSelect(); actbuttons->setImage(0, new QPixmap(":images/mac/stop.png")); actbuttons->setImage(1, new QPixmap(":images/mac/split.png")); actbuttons->setImage(2, new QPixmap(":images/mac/trash.png")); pp->addWidget(actbuttons); lb->addWidget(acts); lb->addStretch(); connect(actbuttons, SIGNAL(clicked(int,bool)), this, SLOT(actionClicked(int))); lb->addWidget(new Spacer(this)); QWidget *viewsel = new QWidget(this); viewsel->setContentsMargins(0,0,0,0); QHBoxLayout *pq = new QHBoxLayout(viewsel); pq->setContentsMargins(0,0,0,0); pq->setSpacing(5); pq->addWidget(sidebar); styleSelector = new QtMacSegmentedButton(2, viewsel); styleSelector->setWidth(80); // actually its 80 but we want a 30px space between is and the searchbox styleSelector->setImage(0, new QPixmap(":images/mac/tabbed.png"), 24); styleSelector->setImage(1, new QPixmap(":images/mac/tiled.png"), 24); pq->addWidget(styleSelector); connect(sidebar, SIGNAL(clicked(bool)), this, SLOT(toggleSidebar())); connect(styleSelector, SIGNAL(clicked(int,bool)), this, SLOT(toggleStyle())); // setup Mac thetoolbar head->addWidget(macAnalButtons); head->addWidget(new Spacer(this)); head->addWidget(new Spacer(this)); head->addWidget(viewsel); #ifdef GC_HAVE_LUCENE SearchFilterBox *searchBox = new SearchFilterBox(this,context,false); QCleanlooksStyle *toolStyle = new QCleanlooksStyle(); searchBox->setStyle(toolStyle); searchBox->setFixedWidth(200); head->addWidget(searchBox); connect(searchBox, SIGNAL(searchResults(QStringList)), this, SLOT(setFilter(QStringList))); connect(searchBox, SIGNAL(searchClear()), this, SLOT(clearFilter())); #endif #endif /*---------------------------------------------------------------------- * Windows and Linux Toolbar *--------------------------------------------------------------------*/ #ifndef Q_OS_MAC head = new GcToolBar(this); QCleanlooksStyle *toolStyle = new QCleanlooksStyle(); QPalette metal; metal.setColor(QPalette::Button, QColor(215,215,215)); // get those icons importIcon = iconFromPNG(":images/mac/download.png"); composeIcon = iconFromPNG(":images/mac/compose.png"); intervalIcon = iconFromPNG(":images/mac/stop.png"); splitIcon = iconFromPNG(":images/mac/split.png"); deleteIcon = iconFromPNG(":images/mac/trash.png"); sidebarIcon = iconFromPNG(":images/mac/sidebar.png"); tabbedIcon = iconFromPNG(":images/mac/tabbed.png"); tiledIcon = iconFromPNG(":images/mac/tiled.png"); QSize isize(19,19); Spacer *spacerl = new Spacer(this); spacerl->setFixedWidth(5); import = new QPushButton(this); import->setIcon(importIcon); import->setIconSize(isize); import->setFixedHeight(25); import->setStyle(toolStyle); import->setToolTip(tr("Download from Device")); import->setPalette(metal); connect(import, SIGNAL(clicked(bool)), this, SLOT(downloadRide())); compose = new QPushButton(this); compose->setIcon(composeIcon); compose->setIconSize(isize); compose->setFixedHeight(25); compose->setStyle(toolStyle); compose->setToolTip(tr("Create Manual Activity")); compose->setPalette(metal); connect(compose, SIGNAL(clicked(bool)), this, SLOT(manualRide())); sidebar = new QPushButton(this); sidebar->setIcon(sidebarIcon); sidebar->setIconSize(isize); sidebar->setFixedHeight(25); sidebar->setStyle(toolStyle); sidebar->setToolTip(tr("Toggle Sidebar")); sidebar->setPalette(metal); connect(sidebar, SIGNAL(clicked(bool)), this, SLOT(toggleSidebar())); actbuttons = new QtSegmentControl(this); actbuttons->setStyle(toolStyle); actbuttons->setIconSize(isize); actbuttons->setCount(3); actbuttons->setSegmentIcon(0, intervalIcon); actbuttons->setSegmentIcon(1, splitIcon); actbuttons->setSegmentIcon(2, deleteIcon); actbuttons->setSelectionBehavior(QtSegmentControl::SelectNone); //wince. spelling. ugh actbuttons->setFixedHeight(25); actbuttons->setSegmentToolTip(0, tr("Find Intervals...")); actbuttons->setSegmentToolTip(1, tr("Split Activity...")); actbuttons->setSegmentToolTip(2, tr("Delete Activity")); actbuttons->setPalette(metal); connect(actbuttons, SIGNAL(segmentSelected(int)), this, SLOT(actionClicked(int))); styleSelector = new QtSegmentControl(this); styleSelector->setStyle(toolStyle); styleSelector->setIconSize(isize); styleSelector->setCount(2); styleSelector->setSegmentIcon(0, tabbedIcon); styleSelector->setSegmentIcon(1, tiledIcon); styleSelector->setSegmentToolTip(0, tr("Tabbed View")); styleSelector->setSegmentToolTip(1, tr("Tiled View")); styleSelector->setSelectionBehavior(QtSegmentControl::SelectOne); //wince. spelling. ugh styleSelector->setFixedHeight(25); styleSelector->setPalette(metal); connect(styleSelector, SIGNAL(segmentSelected(int)), this, SLOT(setStyleFromSegment(int))); //avoid toggle infinitely head->addWidget(spacerl); head->addWidget(import); head->addWidget(compose); head->addWidget(actbuttons); head->addStretch(); head->addWidget(sidebar); head->addWidget(styleSelector); #ifdef GC_HAVE_LUCENE // add a search box on far right, but with a little space too SearchFilterBox *searchBox = new SearchFilterBox(this,context,false); searchBox->setStyle(toolStyle); searchBox->setFixedWidth(200); head->addWidget(searchBox); connect(searchBox, SIGNAL(searchResults(QStringList)), this, SLOT(setFilter(QStringList))); connect(searchBox, SIGNAL(searchClear()), this, SLOT(clearFilter())); #endif Spacer *spacer = new Spacer(this); spacer->setFixedWidth(5); head->addWidget(spacer); #endif /*---------------------------------------------------------------------- * ScopeBar *--------------------------------------------------------------------*/ scopebar = new GcScopeBar(context); connect(scopebar, SIGNAL(selectDiary()), this, SLOT(selectDiary())); connect(scopebar, SIGNAL(selectHome()), this, SLOT(selectHome())); connect(scopebar, SIGNAL(selectAnal()), this, SLOT(selectAnalysis())); connect(scopebar, SIGNAL(selectTrain()), this, SLOT(selectTrain())); // Add chart is on the scope bar chartMenu = new QMenu(this); QCleanlooksStyle *styler = new QCleanlooksStyle(); QPushButton *newchart = new QPushButton("+", this); scopebar->addWidget(newchart); newchart->setStyle(styler); newchart->setFixedHeight(20); newchart->setFixedWidth(24); newchart->setFlat(true); newchart->setFocusPolicy(Qt::NoFocus); newchart->setToolTip(tr("Add Chart")); newchart->setAutoFillBackground(false); newchart->setAutoDefault(false); newchart->setMenu(chartMenu); connect(chartMenu, SIGNAL(aboutToShow()), this, SLOT(setChartMenu())); connect(chartMenu, SIGNAL(triggered(QAction*)), this, SLOT(addChart(QAction*))); /*---------------------------------------------------------------------- * Central Widget *--------------------------------------------------------------------*/ tab = new Tab(context); /*---------------------------------------------------------------------- * Central Widget *--------------------------------------------------------------------*/ QWidget *central = new QWidget(this); setContentsMargins(0,0,0,0); central->setContentsMargins(0,0,0,0); QVBoxLayout *mainLayout = new QVBoxLayout(central); mainLayout->setSpacing(0); mainLayout->setContentsMargins(0,0,0,0); #ifndef Q_OS_MAC // nonmac toolbar on main view -- its not // unified with the title bar. mainLayout->addWidget(head); #endif mainLayout->addWidget(scopebar); mainLayout->addWidget(tab); setCentralWidget(central); /*---------------------------------------------------------------------- * Application Menus *--------------------------------------------------------------------*/ #ifdef WIN32 menuBar()->setStyleSheet("QMenuBar { background: rgba(225,225,225); }" "QMenuBar::item { background: rgba(225,225,225); }"); menuBar()->setContentsMargins(0,0,0,0); #endif QMenu *fileMenu = menuBar()->addMenu(tr("&Athlete")); fileMenu->addAction(tr("&New..."), this, SLOT(newCyclist()), tr("Ctrl+N")); fileMenu->addAction(tr("&Open..."), this, SLOT(openCyclist()), tr("Ctrl+O")); fileMenu->addAction(tr("&Close Window"), this, SLOT(close()), tr ("Ctrl+W")); fileMenu->addAction(tr("&Quit All Windows"), this, SLOT(closeAll()), tr("Ctrl+Q")); QMenu *rideMenu = menuBar()->addMenu(tr("A&ctivity")); rideMenu->addAction(tr("&Download from device..."), this, SLOT(downloadRide()), tr("Ctrl+D")); rideMenu->addAction(tr("&Import from file..."), this, SLOT (importFile()), tr ("Ctrl+I")); rideMenu->addAction(tr("&Manual activity entry..."), this, SLOT(manualRide()), tr("Ctrl+M")); rideMenu->addSeparator (); rideMenu->addAction(tr("&Export..."), this, SLOT(exportRide()), tr("Ctrl+E")); rideMenu->addAction(tr("&Batch export..."), this, SLOT(exportBatch()), tr("Ctrl+B")); rideMenu->addAction(tr("Export Metrics as CSV..."), this, SLOT(exportMetrics()), tr("")); #ifdef GC_HAVE_SOAP rideMenu->addSeparator (); rideMenu->addAction(tr("&Upload to TrainingPeaks"), this, SLOT(uploadTP()), tr("Ctrl+U")); rideMenu->addAction(tr("Down&load from TrainingPeaks..."), this, SLOT(downloadTP()), tr("Ctrl+L")); #endif #ifdef GC_HAVE_LIBOAUTH tweetAction = new QAction(tr("Tweet Activity"), this); connect(tweetAction, SIGNAL(triggered(bool)), this, SLOT(tweetRide())); rideMenu->addAction(tweetAction); shareAction = new QAction(tr("Share (Strava, RideWithGPS, CyclingAnalytics)..."), this); connect(shareAction, SIGNAL(triggered(bool)), this, SLOT(share())); rideMenu->addAction(shareAction); #endif ttbAction = new QAction(tr("Upload to Trainingstagebuch..."), this); connect(ttbAction, SIGNAL(triggered(bool)), this, SLOT(uploadTtb())); rideMenu->addAction(ttbAction); rideMenu->addSeparator (); rideMenu->addAction(tr("&Save activity"), this, SLOT(saveRide()), tr("Ctrl+S")); rideMenu->addAction(tr("D&elete activity..."), this, SLOT(deleteRide())); rideMenu->addAction(tr("Split &activity..."), this, SLOT(splitRide())); rideMenu->addAction(tr("Merge activities..."), this, SLOT(mergeRide())); rideMenu->addSeparator (); QMenu *optionsMenu = menuBar()->addMenu(tr("&Tools")); optionsMenu->addAction(tr("&Options..."), this, SLOT(showOptions())); optionsMenu->addAction(tr("Critical Power Estimator..."), this, SLOT(showTools())); optionsMenu->addAction(tr("Air Density (Rho) Estimator..."), this, SLOT(showRhoEstimator())); optionsMenu->addSeparator(); optionsMenu->addAction(tr("Get &Withings Data..."), this, SLOT (downloadMeasures())); optionsMenu->addAction(tr("Get &Zeo Data..."), this, SLOT (downloadMeasuresFromZeo())); optionsMenu->addSeparator(); optionsMenu->addAction(tr("Create a new workout..."), this, SLOT(showWorkoutWizard())); optionsMenu->addAction(tr("Download workouts from ErgDB..."), this, SLOT(downloadErgDB())); optionsMenu->addAction(tr("Import workouts or videos..."), this, SLOT(importWorkout())); optionsMenu->addAction(tr("Scan disk for videos and workouts..."), this, SLOT(manageLibrary())); #ifdef GC_HAVE_ICAL optionsMenu->addSeparator(); optionsMenu->addAction(tr("Upload Activity to Calendar"), this, SLOT(uploadCalendar()), tr ("")); //optionsMenu->addAction(tr("Import Calendar..."), this, SLOT(importCalendar()), tr ("")); // planned for v3.1 //optionsMenu->addAction(tr("Export Calendar..."), this, SLOT(exportCalendar()), tr ("")); // planned for v3.1 optionsMenu->addAction(tr("Refresh Calendar"), this, SLOT(refreshCalendar()), tr ("")); #endif optionsMenu->addSeparator(); optionsMenu->addAction(tr("Find intervals..."), this, SLOT(addIntervals()), tr ("")); // Add all the data processors to the tools menu const DataProcessorFactory &factory = DataProcessorFactory::instance(); QMap<QString, DataProcessor*> processors = factory.getProcessors(); if (processors.count()) { optionsMenu->addSeparator(); toolMapper = new QSignalMapper(this); // maps each option QMapIterator<QString, DataProcessor*> i(processors); connect(toolMapper, SIGNAL(mapped(const QString &)), this, SLOT(manualProcess(const QString &))); i.toFront(); while (i.hasNext()) { i.next(); // The localized processor name is shown in menu QAction *action = new QAction(QString("%1...").arg(i.value()->name()), this); optionsMenu->addAction(action); connect(action, SIGNAL(triggered()), toolMapper, SLOT(map())); toolMapper->setMapping(action, i.key()); } }
//Huge main function. int main(int argc, char *argv[]) { if (argc < 3){ //if you don't type enough arguments printf("Sockets client, usage:\n"); printf("sockets_client {IP-address} {port} \n"); return 0; } else { free(server); server = malloc((strlen(argv[1] + 1) * sizeof(char))); strcpy(server, argv[1]); portno = atoi(argv[2]); } int c; while(1){ if(screen == 0){ CATEGORY = 8; currentRecord = 0; recordView = 0; xt_par0(XT_CLEAR_SCREEN); lifeTracker(); xt_par2(XT_SET_ROW_COL_POS,row = 8, col = 2); } while(screen == 0) { while((c = getkey()) == KEY_NOTHING); if(c == KEY_F9) screen = 3; else if(c == KEY_F3 && maxRecord > 0 && col == 20) screen = 4; else if(c == KEY_DOWN) { if(col == 2 && row >= 8 && row < catCounter + 7){ xt_par2(XT_SET_ROW_COL_POS,CATEGORY = ++row,col); updateRecords(recordView); } if(col == 20 && row >= 7 && row <= tempCounter * 5 + 1){ if(row < 22){ xt_par2(XT_SET_ROW_COL_POS,row+=5,col); ++currentRecord; } else if(recordView < tempCounter-4){ ++recordView; if(search == 1) searchResults(recordView); else updateRecords(recordView); xt_par2(XT_SET_ROW_COL_POS,row=22,col); ++currentRecord; } } if(col > 94 && col < 120){ if(row == 9) xt_par2(XT_SET_ROW_COL_POS,row = 12,col = 95); else if(row == 12) xt_par2(XT_SET_ROW_COL_POS,row = 13,col = 95); else if(row == 13) xt_par2(XT_SET_ROW_COL_POS,row = 16,col); else if(row < 20) xt_par2(XT_SET_ROW_COL_POS,++row,col); else if(row == 20 && col < 110) xt_par2(XT_SET_ROW_COL_POS,++row,col); else if(row == 20 && col > 110) xt_par2(XT_SET_ROW_COL_POS,++row,col = 109); } } else if(c == KEY_UP){ if(col == 2 && row > 8 && row <= 18){ xt_par2(XT_SET_ROW_COL_POS,CATEGORY = --row,col); updateRecords(recordView); } if(col == 20 && row >= 7 && row < 24){ if(row <= 24 && row > 7){ xt_par2(XT_SET_ROW_COL_POS,row-=5,col); --currentRecord; } else if(recordView > 0){ --recordView; if(search == 1) searchResults(recordView); else updateRecords(recordView); xt_par2(XT_SET_ROW_COL_POS,row=7,col); --currentRecord; } } if(row > 9 && col > 94 && col < 120){ if(row == 12) xt_par2(XT_SET_ROW_COL_POS,row = 9,col = 95); else if(row == 13) xt_par2(XT_SET_ROW_COL_POS,row = 12,col = 95); else if(row == 16) xt_par2(XT_SET_ROW_COL_POS, row = 13, col = 95); else if(row < 22) xt_par2(XT_SET_ROW_COL_POS, --row, col); } } else if(c == KEY_ENTER && col > 94 && col < 120 && row > 12 && row < 18) xt_par2(XT_SET_ROW_COL_POS,++row,col=95); else if((c == KEY_LEFT || c == KEY_RIGHT) && col == 2) { CATEGORY = row; updateRecords(recordView); xt_par2(XT_SET_ROW_COL_POS,row=7,col=20); } else if((c == KEY_LEFT || c == KEY_RIGHT) && col == 20) { xt_par2(XT_SET_ROW_COL_POS,row=CATEGORY,col=2); if (search == 1) clearSearch(); currentRecord = recordView = search = 0; updateRecords(recordView); } else if(c == KEY_LEFT && col >= 95) { if(col > 95) xt_par2(XT_SET_ROW_COL_POS,row,--col); else if(row == 13 && col == 95) xt_par2(XT_SET_ROW_COL_POS,--row,col = 101); else if(row >= 17 && row <= 21 && col == 95) xt_par2(XT_SET_ROW_COL_POS,--row, col = 119); } else if(c == KEY_RIGHT && col > 94) { if(row == 9 && col < 112) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row == 12 && col < 101) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row == 12 && col == 101) xt_par2(XT_SET_ROW_COL_POS,++row,col = 95); else if(row == 13 && col < 112) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row >= 16 && row < 21 && col < 119) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row == 21 && col < 109) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row >= 16 && row <= 21 && col == 119) xt_par2(XT_SET_ROW_COL_POS,++row,col = 95); } else if(c == KEY_DELETE) { putchar(' '); if(row == 9) Category[col - 95] = ' '; else if(row == 12) Title[col - 95] = ' '; else if(row == 13) Title[col - 88] = ' '; else if(row >= 16 && row < 22) Body[(row - 16) * 25 + col - 95] = ' '; } else if(c == KEY_BACKSPACE && col >= 95) { if((row == 9 || row == 12) && col > 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Category[col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if((row == 9 || row == 12) && col == 95) { putchar(' '); Title[col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 13 && col > 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Title[col - 88] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 13 && col == 95) { xt_par2(XT_SET_ROW_COL_POS,--row,col = 101); putchar(' '); Title[col - 88] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row >= 16 && row < 22 && col > 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Body[(row - 16) * 25 + col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 16 && col == 95) { putchar(' '); Body[(row - 16) * 25 + col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row > 16 && row < 22 && col == 95) { xt_par2(XT_SET_ROW_COL_POS,--row,col = 119); putchar(' '); Body[(row - 16) * 25 + col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } } else if((c >= ' ' && c <= '~') && col >= 95 && col < 120){ if(row == 9 && col < 112) { putchar(c); Category[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 9 && col == 112) { putchar(c); Category[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 12 && col < 101) { putchar(c); Title[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 12 && col == 101) { putchar(c); Title[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,++row,col=95); } else if(row == 13 && col < 112) { putchar(c); Title[col - 88] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 13 && col == 112) { putchar(c); Title[col - 88] = c; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row >= 16 && row < 21 && col < 119) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row >= 16 && row < 21 && col == 119) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,++row,col = 95); } else if(row == 21 && col < 109) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 21 && col == 109) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,col); } } else if(c == KEY_F2) screen = 1; else if(c == KEY_F4 && col == 20 && maxRecord != 0) screen = 2; else if(c == KEY_F6) { if(sort == 0){ bubbleSort(); sort = 1; } else if (sort == 1){ bubbleSortTime(); sort = 0; } } else if (c == KEY_F7){ if(col < 95) { xt_par2(XT_SET_ROW_COL_POS,row = 9,col = 95); for(reset = 0; reset < 29; reset++) Title[reset] = ' '; for(reset = 0; reset < 140; reset++) Body[reset] = ' '; for(reset = 0; reset < 16; reset++) Category[reset] = ' '; } else if(Title[0] == ' ' && Body[0] == ' ' && Category[0] == ' ') { xt_par2(XT_SET_ROW_COL_POS,row = CATEGORY,col = 2); clearSearch(); updateRecords(0); } else if(Title[0] != ' ' || Body[0] != ' ' || Category[0] != ' ') { clearSearch(); search = 1; searchResults(0); xt_par2(XT_SET_ROW_COL_POS,row = 7, col = 20); } } } if (screen == 1 || screen == 2){ for(reset = 0; reset < 29; reset++) Title[reset] = ' '; for(reset = 0; reset < 140; reset++) Body[reset] = ' '; for(reset = 0; reset < 16; reset++) Category[reset] = ' '; addScreen(); if (screen == 2){ char TempBodyA[71]; char TempBodyB[71]; int k = 0; while(k != 70) { TempBodyA[k] = ' '; TempBodyB[k] = ' '; k++; } k = 0; xt_par2(XT_SET_ROW_COL_POS, row = 12, col = 25); xt_par0(XT_CH_GREEN); printf("Record %d (%s)", currentRecord+1, catStorage[currentRecord].timedate); //get the time using myui1 xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); printf("%s", catStorage[currentRecord].category); int j = 0; while(catStorage[currentRecord].body[j] != '\0'){ if (j < 70) TempBodyA[j] = catStorage[currentRecord].body[j]; else if (j < 140) TempBodyB[j%70] = catStorage[currentRecord].body[j]; j++; } TempBodyA[70] = '\0'; TempBodyB[70] = '\0'; xt_par2(XT_SET_ROW_COL_POS, row = 16, col = 25); printf("%s", catStorage[currentRecord].subject); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 19, col = 25); printf("%s", TempBodyA); xt_par2(XT_SET_ROW_COL_POS, row = 20, col = 25); printf("%s", TempBodyB); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); strncpy(Title, catStorage[currentRecord].subject, sizeof(Title)); strncpy(Body, catStorage[currentRecord].body, sizeof(Body)); strncpy(Category, catStorage[currentRecord].category, sizeof(Category)); } } while(screen == 1 || screen == 2) { while((c = getkey()) == KEY_NOTHING); if (c == KEY_F9){ screen = 0; xt_par0(XT_CLEAR_SCREEN); } else if (c == KEY_DOWN){ if(row == 14) xt_par2(XT_SET_ROW_COL_POS, row = 16, col = 25); else if(row == 16) xt_par2(XT_SET_ROW_COL_POS,row = 19,col = 25); else if(row < 20) xt_par2(XT_SET_ROW_COL_POS,++row,col); } else if (c == KEY_UP){ if(row == 16) xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); if(row == 19) xt_par2(XT_SET_ROW_COL_POS,row = 16,col = 25); else if(row == 20) xt_par2(XT_SET_ROW_COL_POS,--row,col); } else if(c == KEY_LEFT && col > 25 && col < 95) xt_par2(XT_SET_ROW_COL_POS,row,--col); else if(c == KEY_LEFT && col == 25 && row == 20) xt_par2(XT_SET_ROW_COL_POS,--row,col=94); else if(c == KEY_RIGHT && col > 24 && col < 37 && row == 14) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(c == KEY_RIGHT && col > 24 && col < 53 && row == 16) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(c == KEY_RIGHT && col > 24 && col < 94 && row > 18) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(c == KEY_RIGHT && col == 94 && row == 19) xt_par2(XT_SET_ROW_COL_POS,++row,col=25); else if (c == KEY_ENTER && row > 18 && row < 20) xt_par2(XT_SET_ROW_COL_POS,++row,col=25); else if (c == KEY_BACKSPACE && col >= 25 && col < 95 && ((row > 18 && row < 21) || row == 16 || row == 14)){ if(row == 14 && col > 25 && col < 39) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Category[col - 25] = ' '; } else if(row == 16 && col > 25 && col <= 54) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Title[col - 25] = ' '; } else if(row == 19 && col > 25 && col <= 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Body[col - 25] = ' '; } else if(row == 20 && col > 25 && col <= 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Body[col + 45] = ' '; } else if(row == 20){ xt_par2(XT_SET_ROW_COL_POS,--row,col=94); putchar(' '); Body[69] = ' '; } xt_par2(XT_SET_ROW_COL_POS,row,col); } else if (c == KEY_DELETE) { if(row == 14 && col >= 25 && col < 38) { putchar(' '); Category[col - 25] = ' '; } else if(row == 16 && col >= 25 && col < 54) { putchar(' '); Title[col - 25] = ' '; } else if(row == 19 && col >= 25 && col <= 95) { putchar(' '); Body[col - 25] = ' '; } else if(row == 20 && col >= 25 && col <= 95) { putchar(' '); Body[col + 45] = ' '; } xt_par2(XT_SET_ROW_COL_POS,row,col); } else if((c >= ' ' && c <= '~') && col >= 25 && col < 95) { if(row == 14 && col >= 25 && col < 40) { putchar(c); Category[col - 25] = c; } else if(row == 16 && col >= 25 && col < 54) { putchar(c); Title[col - 25] = c; } else if(row == 19 && col >= 25 && col <= 95) { putchar(c); Body[col - 25] = c; } else if(row == 20 && col >= 25 && col <= 95) { putchar(c); Body[col + 45] = c; } if (col < 94 && !(row == 16 && col > 52) && !(row == 14 && col > 36)){ ++col; } else{ if (row == 19) xt_par2(XT_SET_ROW_COL_POS,++row,col=25); else xt_par2(XT_SET_ROW_COL_POS,row,col); } } else if(c == KEY_F2 && screen == 1 /* && there is a valid title and description */){ //save record to corresponding subject if(Title[0] != ' ' || Body[0] != ' ' || Category[0] != ' ') { removeBlanks(); readmyStoreFromChildSOCKETS("add", Title, Body, Category, NULL); } int k = 0; while(k != 29) Title[k++] = ' '; k = 0; while(k != 140) Body[k++] = ' '; k = 0; while(k != 15) Category[k++] = ' '; maxRecord++; screen = 0; } else if(c == KEY_F2 && screen == 2 /* && there has been a valid change in the record */){ //update record removeBlanks(); char str[80]; for(i = 0; i < maxRecord; i++){ if(strcmp(catStorage[currentRecord].subject, dataStorage[i].subject) == 0 && strcmp(catStorage[currentRecord].body, dataStorage[i].body) == 0 && strcmp(catStorage[currentRecord].category, dataStorage[i].category) == 0 && strcmp(catStorage[currentRecord].timedate, dataStorage[i].timedate) == 0){//looks for corresponding record in the actual record list sprintf(str, "%d", i+1); break; } } readmyStoreFromChildSOCKETS("edit", str, Title, Body, Category); int k = 0; while(k != 29) Title[k++] = ' '; k = 0; while(k != 140) Body[k++] = ' '; k = 0; while(k != 15) Category[k++] = ' '; screen = 0; } } if (screen == 4){ for(reset = 0; reset < 29; reset++) Title[reset] = ' '; for(reset = 0; reset < 140; reset++) Body[reset] = ' '; for(reset = 0; reset < 16; reset++) Category[reset] = ' '; deleteScreen(); if (screen == 4){ char TempBodyA[71]; char TempBodyB[71]; int k = 0; while(k != 70) { TempBodyA[k] = ' '; TempBodyB[k] = ' '; k++; } k = 0; xt_par2(XT_SET_ROW_COL_POS, row = 12, col = 25); xt_par0(XT_CH_GREEN); printf("Record %d (%s)", currentRecord+1, catStorage[currentRecord].timedate); //get the time using myui1 xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); printf("%s", catStorage[currentRecord].category); int j = 0; while(catStorage[currentRecord].body[j] != '\0'){ if (j < 70) TempBodyA[j] = catStorage[currentRecord].body[j]; else if (j < 140) TempBodyB[j%70] = catStorage[currentRecord].body[j]; j++; } TempBodyA[70] = '\0'; TempBodyB[70] = '\0'; xt_par2(XT_SET_ROW_COL_POS, row = 16, col = 25); printf("%s", catStorage[currentRecord].subject); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 19, col = 25); printf("%s", TempBodyA); xt_par2(XT_SET_ROW_COL_POS, row = 20, col = 25); printf("%s", TempBodyB); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); strncpy(Title, catStorage[currentRecord].subject, sizeof(Title)); strncpy(Body, catStorage[currentRecord].body, sizeof(Body)); strncpy(Category, catStorage[currentRecord].category, sizeof(Category)); //print corresponding record in correct locations using myui1 } } while(screen == 4) { while((c = getkey()) == KEY_NOTHING); if (c == KEY_F9){ screen = 0; xt_par0(XT_CLEAR_SCREEN); } else if (c == KEY_F3){ char str[80]; for(i = 0; i < maxRecord; i++){ if(strcmp(catStorage[currentRecord].subject, dataStorage[i].subject) == 0 && strcmp(catStorage[currentRecord].body, dataStorage[i].body) == 0 && strcmp(catStorage[currentRecord].category, dataStorage[i].category) == 0 && strcmp(catStorage[currentRecord].timedate, dataStorage[i].timedate) == 0){ //looks for corresponding record in the actual record list sprintf(str, "%d", i+1); break; } } readmyStoreFromChildSOCKETS("delete", str, NULL, NULL, NULL); maxRecord--; screen = 0; } } if (screen == 3) break; } getkey_terminate(); xt_par0(XT_CLEAR_SCREEN); xt_par0(XT_BG_DEFAULT); xt_par2(XT_SET_ROW_COL_POS,row=1,col=1); getkey_terminate(); return 0; }