Back to index

unity  6.0.0
DndData.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003 * Copyright (C) 2011 Canonical Ltd
00004 *
00005 * This program is free software: you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License version 3 as
00007 * published by the Free Software Foundation.
00008 *
00009 * This program is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 *
00017 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00018 */
00019 
00020 #include "DndData.h"
00021 
00022 #include <cstring>
00023 #include <vector>
00024 
00025 #include <gio/gio.h>
00026 
00027 #include <UnityCore/GLibWrapper.h>
00028 
00029 namespace unity {
00030   
00031 void DndData::Fill(char* uris)
00032 { 
00033   Reset();
00034   
00035   char* pch = strtok (uris, "\r\n");
00036   while (pch != NULL)
00037   {
00038     glib::Object<GFile> file(g_file_new_for_uri(pch));
00039     glib::Object<GFileInfo> info(g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL));
00040     const char* content_type = g_file_info_get_content_type(info);
00041     
00042     uris_.insert(pch);
00043     
00044     if (content_type != NULL)
00045     {
00046       types_.insert(content_type);
00047       uris_to_types_[pch] = content_type;
00048       types_to_uris_[content_type].insert(pch);
00049     }
00050        
00051     pch = strtok (NULL, "\r\n");
00052   }
00053 }
00054 
00055 void DndData::Reset()
00056 {
00057   uris_.clear();
00058   types_.clear();
00059   uris_to_types_.clear();
00060   types_to_uris_.clear();
00061 }
00062 
00063 } // namespace unity