Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • ffe79665bb1ba320420bb6d313547d1e110b9001
  • master par défaut
  • 1-baka-export
  • meson
  • assdraw
  • old-master
  • v3.2.2
  • v3.2.1
  • v3.2.0
  • v3.1.3
  • v3.1.2
  • v3.1.1
  • v3.1.0
  • v3.0.4
  • v3.0.3
  • v3.0.2
  • v3.0.1
  • v3.0.0
  • v2.1.3
  • v2.1.4
  • v2.1.5
  • v2.1.6
  • v2.1.0
  • v2.1.1
  • v2.1.2
  • v2.1.7
26 résultats

timeedit_ctrl.h

Blame
    • Thomas Goyne's avatar
      ffe79665
      Work around wxGTK issues with time edits · ffe79665
      Thomas Goyne a rédigé
      Modifying the contents of a text control after IM processing happens in
      the same cycle of the event loop seems to be seriously broken. Work
      around this by disabling IM processing for time edits, as it should
      never be relevant for them anyway.
      
      Closes #1679. Closes #1680.
      ffe79665
      Historique
      Work around wxGTK issues with time edits
      Thomas Goyne a rédigé
      Modifying the contents of a text control after IM processing happens in
      the same cycle of the event loop seems to be seriously broken. Work
      around this by disabling IM processing for time edits, as it should
      never be relevant for them anyway.
      
      Closes #1679. Closes #1680.
    mod.rs 3,07 Kio
    //! Database implementation in rust for lektor.
    
    pub(self) use diesel::prelude::*;
    use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
    pub(self) use log::*;
    
    pub mod models;
    pub mod schema;
    pub mod unsafe_interface;
    
    use self::models::*;
    
    use crate::{database::schema::kara_tags, kurisu_api::v1 as api_v1};
    
    /// The migrations!
    const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
    
    /// Run migrations in a connexion!
    fn run_migration(conn: &mut SqliteConnection) -> Result<(), String> {
        conn.run_pending_migrations(MIGRATIONS)
            .map_err(|err| err.to_string())
            .map(|_| ())
    }
    
    /// Create a connexion to a database and run automatically the migrations.
    pub fn establish_connection(path: impl AsRef<str>) -> Result<SqliteConnection, String> {
        let mut conn = SqliteConnection::establish(path.as_ref())
            .map_err(|err| format!("error connecting to {}: {}", path.as_ref(), err))?;
        self::run_migration(&mut conn)?;
        Ok(conn)
    }
    
    /// All the information needed to add a kara recieved from a repo!
    pub type NewKaraRequest<'a> = (
        models::NewKaraId,
        models::NewKara<'a>,
        models::NewLanguage<'a>,
        Vec<models::AddKaraMaker<'a>>,
        Vec<models::AddKaraTag>,
    );
    
    pub struct LktDatabaseConnection {
        sqlite: SqliteConnection,
    }
    
    impl LktDatabaseConnection {
        /// Get a tag id by its name.
        pub fn get_tag_id_by_name(&mut self, tag_name: impl AsRef<str>) -> i32 {
            use self::schema::tag::dsl::*;
            tag.filter(name.is(tag_name.as_ref()))
                .first::<Tag>(&mut self.sqlite)
                .unwrap()
                .id
        }
    
        /// Get a free local id for all karas.
        pub fn get_kara_new_local_id(&mut self) -> i32 {
            use self::schema::kara::dsl::*;
            use diesel::dsl::*;
            kara.select(max(id))
                .first::<Option<i32>>(&mut self.sqlite)
                .unwrap()
                .unwrap_or(0)
        }
    
        /// Create a series of models from a kara signature from Kurisu's V1 API.
        pub fn new_kara<'a>(&mut self, repo_id: u64, kara: api_v1::Kara<'a>) -> NewKaraRequest<'a> {
            error!("todo: query the database for a new local id");
            let local_id = self.get_kara_new_local_id();
            let id = NewKaraId {
                repo_id: repo_id as i32,
                local_kara_id: local_id as i32,
                repo_kara_id: kara.id as i32,
            };
            let lang = NewLanguage::from(kara.get_language());
            let kara_makers = vec![AddKaraMaker {
                id: local_id as i32,
                name: kara.author_name,
            }];
            let tags = vec![AddKaraTag {
                kara_id: local_id as i32,
                tag_id: self.get_tag_id_by_name("number"),
                value: Some(format!("{}", kara.song_number)),
            }];
            let kara = NewKara {
                id: local_id as i32,
                song_title: kara.song_name,
                song_type: kara.song_type,
                song_origin: kara.category,
                source_name: kara.source_name,
                language: lang.code,
                file_hash: format!("{}", kara.unix_timestamp),
            };
            (id, kara, lang, kara_makers, tags)
        }
    }