/*
 * Copyright 2014 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *   Charles Kerr <charles.kerr@canonical.com>
 */

#include <transfer/transfer.h>

#include <cstdio> // std::snprintf()

namespace lomiri {
namespace indicator {
namespace transfer {

/***
****
***/

std::string Transfer::next_unique_id()
{
  static unsigned int next = 1000;
  char buf[32];
  std::snprintf(buf, sizeof(buf), "%u", next);
  ++next;
  return buf;
}

bool Transfer::can_start() const
{
  return state==QUEUED;
}

bool Transfer::can_resume() const
{
  return state==PAUSED || state==CANCELED || state==ERROR;
}

bool Transfer::can_pause() const
{
  return state==RUNNING || state==HASHING || state==PROCESSING || state==QUEUED;
}

bool Transfer::can_cancel() const
{
  return state!=FINISHED;
}

bool Transfer::can_clear() const
{
  return state==FINISHED;
}

/***
****
***/

} // namespace transfer
} // namespace indicator
} // namespace lomiri
