Пример #1
0
bool diff_rename(project_t::ref oldproj, project_t *nproj)
{
  const std::string &diff_name = project_diff_name(oldproj.get());
  if(unlikely(diff_name.empty()))
    return false;

  fdguard difffd(oldproj->dirfd, diff_name.c_str(), O_RDONLY);

  /* parse the file and get the DOM */
  xmlDocGuard doc(xmlReadFd(difffd, nullptr, nullptr, XML_PARSE_NONET));
  if(unlikely(!doc)) {
    error_dlg(trstring("Error: could not parse file %1\n").arg(diff_name));
    return false;
  }

  for (xmlNode *cur_node = xmlDocGetRootElement(doc.get()); cur_node != nullptr;
       cur_node = cur_node->next) {
    if (cur_node->type == XML_ELEMENT_NODE) {
      if(likely(strcmp(reinterpret_cast<const char *>(cur_node->name), "diff") == 0)) {
        xmlSetProp(cur_node, BAD_CAST "name", BAD_CAST nproj->name.c_str());
        break;
      }
    }
  }

  xmlSaveFormatFileEnc((nproj->path + diff_filename(nproj)).c_str(), doc.get(), "UTF-8", 1);

  return true;
}
Пример #2
0
static void callback_fetch_mm_clicked(area_context_t *context) {
  dbus_mm_pos_t mmpos;
  if(!dbus_mm_set_position(&mmpos)) {
    error_dlg(_("Unable to communicate with Maemo Mapper. "
              "You need to have Maemo Mapper installed to use this feature."),
              context->dialog.get());
    return;
  }

  if(!mmpos.valid) {
    error_dlg(_("No valid position received yet. You need to "
           "scroll or zoom the Maemo Mapper view in order to force it to send "
           "its current view position to osm2go."), context->dialog.get());
    return;
  }

  /* maemo mapper is fourth tab (page 3) */
  if(!current_tab_is(context, "M.Mapper"))
    return;

  /* maemo mapper pos data ... */
  pos_float_t center_lat = mmpos.pos.lat;
  pos_float_t center_lon = mmpos.pos.lon;
  int zoom = mmpos.zoom;

  if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon))
    return;

  double vscale = DEG2RAD(POS_EQ_RADIUS);
  double height = 8 * (1<<zoom) / vscale;
  context->bounds.min.lat = center_lat - height;
  context->bounds.max.lat = center_lat + height;

  double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS);
  double width  = 16 * (1<<zoom) / hscale;
  context->bounds.min.lon = center_lon - width;
  context->bounds.max.lon = center_lon + width;

  area_main_update(context);

  /* also update other tabs */
  direct_update(context);
  extent_update(context);
  map_update(context, false);
}
Пример #3
0
unsigned int project_t::diff_restore()
{
  const std::string &diff_name = project_diff_name(this);
  if(diff_name.empty()) {
    printf("no diff present!\n");
    return DIFF_NONE_PRESENT;
  }

  fdguard difffd(dirfd, diff_name.c_str(), O_RDONLY);

  /* parse the file and get the DOM */
  xmlDocGuard doc(xmlReadFd(difffd, nullptr, nullptr, XML_PARSE_NONET));
  if(unlikely(!doc)) {
    error_dlg(trstring("Error: could not parse file %1\n").arg(diff_name));
    return DIFF_INVALID;
  }

  printf("diff %s found, applying ...\n", diff_name.c_str());

  unsigned int res = DIFF_RESTORED;

  for (xmlNode *cur_node = xmlDocGetRootElement(doc.get()); cur_node != nullptr;
       cur_node = cur_node->next) {
    if (cur_node->type == XML_ELEMENT_NODE) {
      if(strcmp(reinterpret_cast<const char *>(cur_node->name), "diff") == 0) {
        xmlString str(xmlGetProp(cur_node, BAD_CAST "name"));
        if(!str.empty()) {
          const char *cstr = str;
          printf("diff for project %s\n", cstr);
          if(unlikely(name != cstr)) {
            warning_dlg(trstring("Diff name (%1) does not match project name (%2)").arg(cstr).arg(name));
            res |= DIFF_PROJECT_MISMATCH;
          }
        }

        for(xmlNodePtr node_node = cur_node->children; node_node != nullptr;
            node_node = node_node->next) {
          if(node_node->type == XML_ELEMENT_NODE) {
            if(strcmp(reinterpret_cast<const char *>(node_node->name), node_t::api_string()) == 0)
              diff_restore_node(node_node, osm);

            else if(strcmp(reinterpret_cast<const char *>(node_node->name), way_t::api_string()) == 0)
              diff_restore_way(node_node, osm);

            else if(likely(strcmp(reinterpret_cast<const char *>(node_node->name), relation_t::api_string()) == 0))
              diff_restore_relation(node_node, osm);

            else {
	      printf("WARNING: item %s not restored\n", node_node->name);
              res |= DIFF_ELEMENTS_IGNORED;
            }
	  }
	}
      }
    }
  }

  /* check for hidden ways and update menu accordingly */
  if(osm->hasHiddenWays())
    res |= DIFF_HAS_HIDDEN;

  return res;
}
Пример #4
0
HANDLE WINAPI OpenW(const OpenInfo* info) {
  try {
    if (info->OpenFrom == OPEN_COMMANDLINE) {
      // test if plugin is already open on active panel
      for (unsigned i = 0; i < g_plugin_objects.size(); i++) {
        PanelInfo pi;
        if (far_control_ptr(g_plugin_objects[i], FCTL_GETPANELINFO, &pi)) {
          if (pi.Flags & PFLAGS_FOCUS) {
            // change current directory of active plugin
            set_dir(g_plugin_objects[i], reinterpret_cast<OpenCommandLineInfo*>(info->Data)->CommandLine, true);
            far_control_int(INVALID_HANDLE_VALUE, FCTL_UPDATEPANEL, 0);
            PanelRedrawInfo pri = { sizeof(PanelRedrawInfo) };
            pri.CurrentItem = 0;
            pri.TopPanelItem = 0;
            far_control_ptr(INVALID_HANDLE_VALUE, FCTL_REDRAWPANEL, &pri);
            // do not create new plugin instance
            return nullptr;
          }
        }
      }
    }
    init_if_needed();
    ObjectArray<DeviceInfo> dev_list;
    get_device_list(dev_list);
    if (dev_list.size() == 0) FAIL(MsgError(far_get_msg(MSG_ERR_NO_DEVICE)));
    intptr_t mi = 0;
    if (dev_list.size() > 1) {
      ObjectArray<UnicodeString> menu_str;
      for (unsigned i = 0; i < dev_list.size(); i++) {
        menu_str += UnicodeString::format(L"%S %S (%S)", &dev_list[i].name, &dev_list[i].platform, &dev_list[i].con_type);
      }
      mi = far_menu(c_device_list_menu_guid, far_get_msg(MSG_DEVICE_LIST_TITLE), menu_str);
      if (mi == -1) BREAK;
    }
    PluginInstance* plugin = new PluginInstance();
    try {
      plugin->device_info = dev_list[mi];
      create_session(plugin->device_info.id, plugin);
      if (info->OpenFrom == OPEN_COMMANDLINE) {
        // directory is specified on command line
        plugin->current_dir = reinterpret_cast<OpenCommandLineInfo*>(info->Data)->CommandLine;
        if (!dir_exists(plugin->current_dir, plugin->session)) plugin->current_dir = L"\\";
      }
      else if (g_plugin_options.save_last_dir) {
        // restore last directory
        plugin->current_dir = load_last_dir(plugin->device_info.strid());
        if (!dir_exists(plugin->current_dir, plugin->session)) plugin->current_dir = L"\\";
      }
      else {
        plugin->current_dir = L"\\";
      }
      NOFAIL(refresh_system_info(plugin));
      g_plugin_objects += plugin;
    }
    catch (...) {
      delete plugin;
      throw;
    }
    return plugin;
  }
  catch (Break&) {
  }
  catch (MsgError& e) {
    msg_dlg(e.message());
  }
  catch (Error& e) {
    LOG_ERR(e);
    error_dlg(e, far_get_msg(MSG_ERR_PLUGIN_INIT));
  }
  catch (...) {
    far_message(c_error_dialog_guid, L"\nFailure!", 0, FMSG_WARNING | FMSG_MB_OK);
  }
  return nullptr;
}