LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXRecentNetworks.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 78.6 % 28 22
Test Date: 2024-11-22 15:46:21 Functions: 66.7 % 6 4

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2004-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MFXRecentNetworks.cpp
      15              : /// @author  Pablo Alvarez Lopez
      16              : /// @date    Feb 2021
      17              : ///
      18              : //
      19              : /****************************************************************************/
      20              : 
      21              : 
      22              : #include "MFXRecentNetworks.h"
      23              : 
      24              : // ===========================================================================
      25              : // FOX callback mapping
      26              : // ===========================================================================
      27              : 
      28              : FXDEFMAP(MFXRecentNetworks) MFXRecentNetworksMap[] = {
      29              :     FXMAPFUNC(SEL_UPDATE,   MFXRecentNetworks::ID_NOFILES,   MFXRecentNetworks::onUpdNoFiles),
      30              :     FXMAPFUNCS(SEL_UPDATE,  FXRecentFiles::ID_FILE_1,       FXRecentFiles::ID_FILE_10,  MFXRecentNetworks::onUpdFile),
      31              : };
      32              : 
      33              : // Object implementation
      34     13995001 : FXIMPLEMENT(MFXRecentNetworks, FXRecentFiles, MFXRecentNetworksMap, ARRAYNUMBER(MFXRecentNetworksMap))
      35              : 
      36              : // ===========================================================================
      37              : // member method definitions
      38              : // ===========================================================================
      39              : 
      40            0 : MFXRecentNetworks::MFXRecentNetworks() :
      41            0 :     FXRecentFiles() {
      42            0 : }
      43              : 
      44              : 
      45        15102 : MFXRecentNetworks::MFXRecentNetworks(FXApp* a, const FXString& gp) :
      46        15102 :     FXRecentFiles(a, gp) {
      47        15102 : }
      48              : 
      49              : 
      50              : long
      51     11348880 : MFXRecentNetworks::onUpdFile(FXObject* obj, FXSelector sel, void*) {
      52              :     // get filename index
      53     11348880 :     const FXint which = FXSELID(sel) - ID_FILE_1 + 1;
      54              :     // get filename
      55              :     const FXchar* filename;
      56              :     FXchar key[20];
      57              :     sprintf(key, "FILE%d", which);
      58     11348880 :     filename = getApp()->reg().readStringEntry(getGroupName().text(), key, NULL);
      59              :     // update myIndexFilenames
      60     11348880 :     myIndexFilenames[which] = filename;
      61              :     // check filename
      62     11348880 :     if (filename) {
      63     11348880 :         FXString string;
      64     11348880 :         if (which < 10) {
      65     10214310 :             string.format("&%d %s", which, filename);
      66              :         } else {
      67      1134570 :             string.format("1&0 %s", filename);
      68              :         }
      69     11348880 :         obj->handle(this, FXSEL(SEL_COMMAND, FXWindow::ID_SETSTRINGVALUE), (void*)&string);
      70     11348880 :         obj->handle(this, FXSEL(SEL_COMMAND, FXWindow::ID_SHOW), NULL);
      71     11348880 :     } else {
      72            0 :         obj->handle(this, FXSEL(SEL_COMMAND, FXWindow::ID_HIDE), NULL);
      73              :     }
      74     11348880 :     return 1;
      75              : }
      76              : 
      77              : 
      78              : long
      79      1134469 : MFXRecentNetworks::onUpdNoFiles(FXObject* obj, FXSelector, void*) {
      80              :     // first disable object
      81      1134469 :     obj->handle(obj, FXSEL(SEL_COMMAND, FXWindow::ID_DISABLE), NULL);
      82              :     // iterate over myIndexFilenames
      83      1134469 :     for (const auto& indexFilename : myIndexFilenames) {
      84              :         // if filename isn't empty, then hide object and stop
      85      1134469 :         if (!indexFilename.second.empty()) {
      86      1134469 :             obj->handle(obj, FXSEL(SEL_COMMAND, FXWindow::ID_HIDE), NULL);
      87              :             return 1;
      88              :         }
      89              :     }
      90              :     //show object
      91            0 :     obj->handle(obj, FXSEL(SEL_COMMAND, FXWindow::ID_SHOW), NULL);
      92            0 :     return 1;
      93              : }
        

Generated by: LCOV version 2.0-1